Commit fa2d1b2316
Verified · cmc
internal/control/admin.go +8 −8
| @@ -131,7 +131,7 @@ func runAdminUserShow(c *Ctx, args []string) int { | ||
| 131 | 131 | return code |
| 132 | 132 | } |
| 133 | 133 | if len(args) != 1 { |
| 134 | return c.fail(protocol.ExitUsage, "usage: admin user show <username>") | |
| 134 | return c.usage() | |
| 135 | 135 | } |
| 136 | 136 | name := args[0] |
| 137 | 137 | u, err := c.Store.UserByUsername(name) |
| @@ -291,7 +291,7 @@ func setAdmin(c *Ctx, args []string, admin bool) int { | ||
| 291 | 291 | verb = "promote" |
| 292 | 292 | } |
| 293 | 293 | if len(args) != 1 { |
| 294 | return c.fail(protocol.ExitUsage, "usage: admin user %s <username>", verb) | |
| 294 | return c.usage() | |
| 295 | 295 | } |
| 296 | 296 | u, err := c.Store.UserByUsername(args[0]) |
| 297 | 297 | if errors.Is(err, store.ErrNotFound) { |
| @@ -389,7 +389,7 @@ func adminArchive(c *Ctx, args []string, archived bool) int { | ||
| 389 | 389 | verb = "unarchive" |
| 390 | 390 | } |
| 391 | 391 | if len(args) != 1 { |
| 392 | return c.fail(protocol.ExitUsage, "usage: admin repo %s <owner/name>", verb) | |
| 392 | return c.usage() | |
| 393 | 393 | } |
| 394 | 394 | repo, code := adminRepo(c, args[0]) |
| 395 | 395 | if code >= 0 { |
| @@ -404,7 +404,7 @@ func adminArchive(c *Ctx, args []string, archived bool) int { | ||
| 404 | 404 | |
| 405 | 405 | func runAdminRepoVisibility(c *Ctx, args []string) int { |
| 406 | 406 | if len(args) != 2 || (args[1] != "public" && args[1] != "private") { |
| 407 | return c.fail(protocol.ExitUsage, "usage: admin repo visibility <owner/name> public|private") | |
| 407 | return c.usage() | |
| 408 | 408 | } |
| 409 | 409 | repo, code := adminRepo(c, args[0]) |
| 410 | 410 | if code >= 0 { |
| @@ -426,11 +426,11 @@ func runAdminRepoDelete(c *Ctx, args []string) int { | ||
| 426 | 426 | } else if path == "" { |
| 427 | 427 | path = a |
| 428 | 428 | } else { |
| 429 | return c.fail(protocol.ExitUsage, "usage: admin repo delete <owner/name> --yes") | |
| 429 | return c.usage() | |
| 430 | 430 | } |
| 431 | 431 | } |
| 432 | 432 | if path == "" { |
| 433 | return c.fail(protocol.ExitUsage, "usage: admin repo delete <owner/name> --yes") | |
| 433 | return c.usage() | |
| 434 | 434 | } |
| 435 | 435 | repo, code := adminRepo(c, path) |
| 436 | 436 | if code >= 0 { |
| @@ -451,7 +451,7 @@ func runAdminRunnersForget(c *Ctx, args []string) int { | ||
| 451 | 451 | return code |
| 452 | 452 | } |
| 453 | 453 | if len(args) != 1 { |
| 454 | return c.fail(protocol.ExitUsage, "usage: admin runners forget <fingerprint>") | |
| 454 | return c.usage() | |
| 455 | 455 | } |
| 456 | 456 | if err := c.Store.ForgetRunner(args[0]); err != nil { |
| 457 | 457 | if errors.Is(err, store.ErrNotFound) { |
| @@ -470,7 +470,7 @@ func runAdminRunners(c *Ctx, args []string) int { | ||
| 470 | 470 | return code |
| 471 | 471 | } |
| 472 | 472 | if len(args) != 0 { |
| 473 | return c.fail(protocol.ExitUsage, "usage: admin runners") | |
| 473 | return c.usage() | |
| 474 | 474 | } |
| 475 | 475 | runners, err := c.Store.ListRunners() |
| 476 | 476 | if err != nil { |
internal/control/adminhost.go +7 −8
| @@ -55,8 +55,7 @@ func runAdminUserCreate(c *Ctx, args []string) int { | ||
| 55 | 55 | if code := requireInstanceAdmin(c); code >= 0 { |
| 56 | 56 | return code |
| 57 | 57 | } |
| 58 | const usage = "usage: admin user create <username> [--admin] [--email <address> [--verified]] [--key -] < key.pub" | |
| 59 | f, err := parseFlags(args, flagSpec{Values: []string{"--email", "--key"}, Bools: []string{"--admin", "--verified"}, MaxPos: 1, Usage: usage}) | |
| 58 | f, err := parseFlags(args, flagSpec{Values: []string{"--email", "--key"}, Bools: []string{"--admin", "--verified"}, MaxPos: 1, Usage: c.Cmd.Usage}) | |
| 60 | 59 | if err != nil { |
| 61 | 60 | return c.fail(protocol.ExitUsage, "%v", err) |
| 62 | 61 | } |
| @@ -66,10 +65,10 @@ func runAdminUserCreate(c *Ctx, args []string) int { | ||
| 66 | 65 | return c.fail(protocol.ExitUsage, "--key only supports - (the public key on stdin)") |
| 67 | 66 | } |
| 68 | 67 | if username == "" || username[0] == '-' { |
| 69 | return c.fail(protocol.ExitUsage, usage) | |
| 68 | return c.usage() | |
| 70 | 69 | } |
| 71 | 70 | if username == "" || (verified && email == "") { |
| 72 | return c.fail(protocol.ExitUsage, usage) | |
| 71 | return c.usage() | |
| 73 | 72 | } |
| 74 | 73 | if err := policy.ValidateOwnerName(username); err != nil { |
| 75 | 74 | return c.failInput(err) |
| @@ -128,7 +127,7 @@ func adminUserArg(c *Ctx, args []string, usage string) (store.User, int) { | ||
| 128 | 127 | return store.User{}, code |
| 129 | 128 | } |
| 130 | 129 | if len(args) != 1 { |
| 131 | return store.User{}, c.fail(protocol.ExitUsage, "usage: %s", usage) | |
| 130 | return store.User{}, c.usage() | |
| 132 | 131 | } |
| 133 | 132 | u, err := c.Store.UserByUsername(args[0]) |
| 134 | 133 | if errors.Is(err, store.ErrNotFound) { |
| @@ -201,7 +200,7 @@ func runAdminEmailVerify(c *Ctx, args []string) int { | ||
| 201 | 200 | return code |
| 202 | 201 | } |
| 203 | 202 | if len(args) != 2 { |
| 204 | return c.fail(protocol.ExitUsage, "usage: admin email verify <username> <address>") | |
| 203 | return c.usage() | |
| 205 | 204 | } |
| 206 | 205 | u, err := c.Store.UserByUsername(args[0]) |
| 207 | 206 | if errors.Is(err, store.ErrNotFound) { |
| @@ -228,7 +227,7 @@ func runAdminInvite(c *Ctx, args []string) int { | ||
| 228 | 227 | email = args[1] |
| 229 | 228 | } |
| 230 | 229 | if email == "" { |
| 231 | return c.fail(protocol.ExitUsage, "usage: admin invite --email <address>") | |
| 230 | return c.usage() | |
| 232 | 231 | } |
| 233 | 232 | if used, err := c.Store.EmailInUse(email); err != nil { |
| 234 | 233 | return c.fail(protocol.ExitFailure, "%v", err) |
| @@ -271,7 +270,7 @@ func runAdminStats(c *Ctx, args []string) int { | ||
| 271 | 270 | return code |
| 272 | 271 | } |
| 273 | 272 | if len(args) != 0 { |
| 274 | return c.fail(protocol.ExitUsage, "usage: admin stats") | |
| 273 | return c.usage() | |
| 275 | 274 | } |
| 276 | 275 | counts, err := c.Store.InstanceCounts() |
| 277 | 276 | if err != nil { |
internal/control/audit.go +1 −3
| @@ -18,14 +18,12 @@ func init() { | ||
| 18 | 18 | ReadOnly: true, SSHOnly: true, Run: runAudit}) |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | const auditUsage = "usage: audit [--actor <user>|-] [--action <prefix>] [--since <duration|date>] [--limit <n>]" | |
| 22 | ||
| 23 | 21 | func runAudit(c *Ctx, args []string) int { |
| 24 | 22 | if !c.User.IsAdmin { |
| 25 | 23 | return c.fail(protocol.ExitDenied, "the audit log is for instance admins") |
| 26 | 24 | } |
| 27 | 25 | f := store.AuditFilter{Limit: 100} |
| 28 | fl, err := parseFlags(args, flagSpec{Values: []string{"--limit", "--actor", "--action", "--since"}, MaxPos: 0, Usage: auditUsage}) | |
| 26 | fl, err := parseFlags(args, flagSpec{Values: []string{"--limit", "--actor", "--action", "--since"}, MaxPos: 0, Usage: c.Cmd.Usage}) | |
| 29 | 27 | if err != nil { |
| 30 | 28 | return c.fail(protocol.ExitUsage, "%v", err) |
| 31 | 29 | } |
internal/control/build.go +8 −8
| @@ -104,7 +104,7 @@ func buildRef(c *Ctx, args []string) (store.Repo, store.Build, int) { | ||
| 104 | 104 | |
| 105 | 105 | func runBuildList(c *Ctx, args []string) int { |
| 106 | 106 | if len(args) != 1 { |
| 107 | return c.fail(protocol.ExitUsage, "usage: build list <owner/name>") | |
| 107 | return c.usage() | |
| 108 | 108 | } |
| 109 | 109 | repo, code := resolveRepo(c, args[0], policy.CanRead) |
| 110 | 110 | if code >= 0 { |
| @@ -182,7 +182,7 @@ func repoJobs(c *Ctx, repo store.Repo) ([]ci.Job, string, int) { | ||
| 182 | 182 | // that can read the repository's git could offer the choice. |
| 183 | 183 | func runBuildJobs(c *Ctx, args []string) int { |
| 184 | 184 | if len(args) != 1 { |
| 185 | return c.fail(protocol.ExitUsage, "usage: build jobs <owner/name>") | |
| 185 | return c.usage() | |
| 186 | 186 | } |
| 187 | 187 | repo, code := resolveRepo(c, args[0], policy.CanRead) |
| 188 | 188 | if code >= 0 { |
| @@ -212,7 +212,7 @@ func runBuildJobs(c *Ctx, args []string) int { | ||
| 212 | 212 | |
| 213 | 213 | func runBuildTrigger(c *Ctx, args []string) int { |
| 214 | 214 | if len(args) != 2 { |
| 215 | return c.fail(protocol.ExitUsage, "usage: build trigger <owner/name> <job>") | |
| 215 | return c.usage() | |
| 216 | 216 | } |
| 217 | 217 | repo, code := resolveRepo(c, args[0], policy.CanWrite) |
| 218 | 218 | if code >= 0 { |
| @@ -246,7 +246,7 @@ var secretName = regexp.MustCompile(`^[A-Z_][A-Z0-9_]{0,63}$`) | ||
| 246 | 246 | |
| 247 | 247 | func runSecretSet(c *Ctx, args []string) int { |
| 248 | 248 | if len(args) != 2 { |
| 249 | return c.fail(protocol.ExitUsage, "usage: repo secret set <owner/name> <NAME> (value on stdin)") | |
| 249 | return c.usage() | |
| 250 | 250 | } |
| 251 | 251 | if !secretName.MatchString(args[1]) { |
| 252 | 252 | return c.fail(protocol.ExitUsage, "secret names are env-var shaped: uppercase letters, digits, _") |
| @@ -273,7 +273,7 @@ func runSecretSet(c *Ctx, args []string) int { | ||
| 273 | 273 | |
| 274 | 274 | func runSecretRemove(c *Ctx, args []string) int { |
| 275 | 275 | if len(args) != 2 { |
| 276 | return c.fail(protocol.ExitUsage, "usage: repo secret remove <owner/name> <NAME>") | |
| 276 | return c.usage() | |
| 277 | 277 | } |
| 278 | 278 | repo, code := resolveRepo(c, args[0], policy.CanAdmin) |
| 279 | 279 | if code >= 0 { |
| @@ -292,7 +292,7 @@ func runSecretRemove(c *Ctx, args []string) int { | ||
| 292 | 292 | |
| 293 | 293 | func runSecretList(c *Ctx, args []string) int { |
| 294 | 294 | if len(args) != 1 { |
| 295 | return c.fail(protocol.ExitUsage, "usage: repo secret list <owner/name>") | |
| 295 | return c.usage() | |
| 296 | 296 | } |
| 297 | 297 | repo, code := resolveRepo(c, args[0], policy.CanAdmin) |
| 298 | 298 | if code >= 0 { |
| @@ -464,7 +464,7 @@ func runRunnerLog(c *Ctx, args []string) int { | ||
| 464 | 464 | return code |
| 465 | 465 | } |
| 466 | 466 | if len(args) != 1 { |
| 467 | return c.fail(protocol.ExitUsage, "usage: runner log <build-id> (chunk on stdin)") | |
| 467 | return c.usage() | |
| 468 | 468 | } |
| 469 | 469 | id, err := strconv.ParseInt(args[0], 10, 64) |
| 470 | 470 | if err != nil { |
| @@ -542,7 +542,7 @@ func runRunnerDone(c *Ctx, args []string) int { | ||
| 542 | 542 | return code |
| 543 | 543 | } |
| 544 | 544 | if len(args) != 2 || (args[1] != "success" && args[1] != "failure") { |
| 545 | return c.fail(protocol.ExitUsage, "usage: runner done <build-id> success|failure") | |
| 545 | return c.usage() | |
| 546 | 546 | } |
| 547 | 547 | id, err := strconv.ParseInt(args[0], 10, 64) |
| 548 | 548 | if err != nil { |
internal/control/commitfile.go +2 −3
| @@ -35,15 +35,14 @@ const maxCommitFileBytes = 1 << 20 | ||
| 35 | 35 | // A repository that requires verified signatures therefore refuses the |
| 36 | 36 | // command rather than writing a commit its own policy would reject. |
| 37 | 37 | func runCommitFile(c *Ctx, args []string) int { |
| 38 | const usage = "repo commit-file <owner/name> <path> --ref <branch> [--message <m>] [--file -]" | |
| 39 | f, err := parseFlags(args, flagSpec{Values: []string{"--ref", "--message", "--file"}, MaxPos: -1, Usage: usage}) | |
| 38 | f, err := parseFlags(args, flagSpec{Values: []string{"--ref", "--message", "--file"}, MaxPos: -1, Usage: c.Cmd.Usage}) | |
| 40 | 39 | if err != nil { |
| 41 | 40 | return c.fail(protocol.ExitUsage, "%v", err) |
| 42 | 41 | } |
| 43 | 42 | rest := f.Pos |
| 44 | 43 | ref, message, file := f.Value("--ref"), f.Value("--message"), f.Value("--file") |
| 45 | 44 | if len(rest) != 2 || ref == "" { |
| 46 | return c.fail(protocol.ExitUsage, "usage: %s", usage) | |
| 45 | return c.usage() | |
| 47 | 46 | } |
| 48 | 47 | repo, code := resolveRepo(c, rest[0], policy.CanWrite) |
| 49 | 48 | if code >= 0 { |
internal/control/control.go +10
| @@ -36,6 +36,15 @@ type Ctx struct { | ||
| 36 | 36 | // Source identifies the credential behind this session for the audit |
| 37 | 37 | // log: an SSH key fingerprint, or "api" for token requests. |
| 38 | 38 | Source string |
| 39 | // Cmd is the command being run, set by Dispatch, so a usage error can | |
| 40 | // print the registered usage rather than a copy of it. | |
| 41 | Cmd Command | |
| 42 | } | |
| 43 | ||
| 44 | // usage reports a bad invocation with the command's registered usage, | |
| 45 | // the one source of it. | |
| 46 | func (c *Ctx) usage() int { | |
| 47 | return c.fail(protocol.ExitUsage, "usage: %s", c.Cmd.Usage) | |
| 39 | 48 | } |
| 40 | 49 | |
| 41 | 50 | type Command struct { |
| @@ -82,6 +91,7 @@ func Dispatch(c *Ctx, argv []string) int { | ||
| 82 | 91 | return c.fail(protocol.ExitUsage, "no command given; try: ssh <host> help") |
| 83 | 92 | } |
| 84 | 93 | cmd, rest, ok := Lookup(argv) |
| 94 | c.Cmd = cmd | |
| 85 | 95 | if !ok { |
| 86 | 96 | return c.fail(protocol.ExitUsage, "unknown command %q", argv[0]) |
| 87 | 97 | } |
internal/control/dashboard.go +2 −2
| @@ -84,7 +84,7 @@ type DashboardOut struct { | ||
| 84 | 84 | |
| 85 | 85 | func runDashboard(c *Ctx, args []string) int { |
| 86 | 86 | if len(args) != 0 { |
| 87 | return c.fail(protocol.ExitUsage, "usage: dashboard") | |
| 87 | return c.usage() | |
| 88 | 88 | } |
| 89 | 89 | d := DashboardOut{ |
| 90 | 90 | Reviews: []DashboardItem{}, Assigned: []DashboardItem{}, MRs: []DashboardItem{}, |
| @@ -260,7 +260,7 @@ func runFeed(c *Ctx, args []string) int { | ||
| 260 | 260 | return code |
| 261 | 261 | } |
| 262 | 262 | if len(rest) != 0 { |
| 263 | return c.fail(protocol.ExitUsage, "usage: feed [--limit <n>] [--cursor <c>]") | |
| 263 | return c.usage() | |
| 264 | 264 | } |
| 265 | 265 | if p.limit == 0 { |
| 266 | 266 | p.limit = feedDefaultLimit |
internal/control/deploykey.go +4 −4
| @@ -34,13 +34,13 @@ func runDeployKeyAdd(c *Ctx, args []string) int { | ||
| 34 | 34 | mode = "rw" |
| 35 | 35 | default: |
| 36 | 36 | if path != "" { |
| 37 | return c.fail(protocol.ExitUsage, "usage: repo deploy-key add <owner/name> [--rw] < key.pub") | |
| 37 | return c.usage() | |
| 38 | 38 | } |
| 39 | 39 | path = a |
| 40 | 40 | } |
| 41 | 41 | } |
| 42 | 42 | if path == "" { |
| 43 | return c.fail(protocol.ExitUsage, "usage: repo deploy-key add <owner/name> [--rw] < key.pub") | |
| 43 | return c.usage() | |
| 44 | 44 | } |
| 45 | 45 | repo, code := resolveRepo(c, path, policy.CanAdmin) |
| 46 | 46 | if code >= 0 { |
| @@ -73,7 +73,7 @@ func runDeployKeyAdd(c *Ctx, args []string) int { | ||
| 73 | 73 | |
| 74 | 74 | func runDeployKeyList(c *Ctx, args []string) int { |
| 75 | 75 | if len(args) != 1 { |
| 76 | return c.fail(protocol.ExitUsage, "usage: repo deploy-key list <owner/name>") | |
| 76 | return c.usage() | |
| 77 | 77 | } |
| 78 | 78 | repo, code := resolveRepo(c, args[0], policy.CanAdmin) |
| 79 | 79 | if code >= 0 { |
| @@ -106,7 +106,7 @@ func runDeployKeyList(c *Ctx, args []string) int { | ||
| 106 | 106 | |
| 107 | 107 | func runDeployKeyRemove(c *Ctx, args []string) int { |
| 108 | 108 | if len(args) != 2 { |
| 109 | return c.fail(protocol.ExitUsage, "usage: repo deploy-key remove <owner/name> <fingerprint>") | |
| 109 | return c.usage() | |
| 110 | 110 | } |
| 111 | 111 | repo, code := resolveRepo(c, args[0], policy.CanAdmin) |
| 112 | 112 | if code >= 0 { |
internal/control/deps.go +3 −3
| @@ -46,7 +46,7 @@ type DepBehind struct { | ||
| 46 | 46 | |
| 47 | 47 | func runDepsEnable(c *Ctx, args []string) int { |
| 48 | 48 | if len(args) != 1 { |
| 49 | return c.fail(protocol.ExitUsage, "usage: repo deps enable <owner/name>") | |
| 49 | return c.usage() | |
| 50 | 50 | } |
| 51 | 51 | repo, code := resolveRepo(c, args[0], policy.CanAdmin) |
| 52 | 52 | if code >= 0 { |
| @@ -62,7 +62,7 @@ func runDepsEnable(c *Ctx, args []string) int { | ||
| 62 | 62 | |
| 63 | 63 | func runDepsDisable(c *Ctx, args []string) int { |
| 64 | 64 | if len(args) != 1 { |
| 65 | return c.fail(protocol.ExitUsage, "usage: repo deps disable <owner/name>") | |
| 65 | return c.usage() | |
| 66 | 66 | } |
| 67 | 67 | repo, code := resolveRepo(c, args[0], policy.CanAdmin) |
| 68 | 68 | if code >= 0 { |
| @@ -78,7 +78,7 @@ func runDepsDisable(c *Ctx, args []string) int { | ||
| 78 | 78 | |
| 79 | 79 | func runDepsStatus(c *Ctx, args []string) int { |
| 80 | 80 | if len(args) != 1 { |
| 81 | return c.fail(protocol.ExitUsage, "usage: repo deps status <owner/name>") | |
| 81 | return c.usage() | |
| 82 | 82 | } |
| 83 | 83 | repo, code := resolveRepo(c, args[0], policy.CanRead) |
| 84 | 84 | if code >= 0 { |
internal/control/diffcomment.go +2 −2
| @@ -143,7 +143,7 @@ func runMRThreads(c *Ctx, args []string) int { | ||
| 143 | 143 | return code |
| 144 | 144 | } |
| 145 | 145 | if len(args) != 2 { |
| 146 | return c.fail(protocol.ExitUsage, "usage: mr threads <owner/name> <n>") | |
| 146 | return c.usage() | |
| 147 | 147 | } |
| 148 | 148 | comments, err := c.Store.ListDiffComments(mr.ID, c.User.ID) |
| 149 | 149 | if err != nil { |
| @@ -202,7 +202,7 @@ func runMRThreads(c *Ctx, args []string) int { | ||
| 202 | 202 | |
| 203 | 203 | func setThreadResolved(c *Ctx, args []string, resolved bool) int { |
| 204 | 204 | if len(args) != 3 { |
| 205 | return c.fail(protocol.ExitUsage, "usage: mr resolve|unresolve <owner/name> <n> <thread-id>") | |
| 205 | return c.usage() | |
| 206 | 206 | } |
| 207 | 207 | repo, mr, code := mrRef(c, args[:2], policy.CanRead) |
| 208 | 208 | if code >= 0 { |
internal/control/explore.go +3 −4
| @@ -37,7 +37,7 @@ func runExplore(c *Ctx, args []string) int { | ||
| 37 | 37 | return code |
| 38 | 38 | } |
| 39 | 39 | if len(rest) != 0 { |
| 40 | return c.fail(protocol.ExitUsage, "usage: explore [--limit <n>] [--cursor <c>]") | |
| 40 | return c.usage() | |
| 41 | 41 | } |
| 42 | 42 | repos, err := c.Store.ListPublicRepos() |
| 43 | 43 | if err != nil { |
| @@ -79,14 +79,13 @@ func runExplore(c *Ctx, args []string) int { | ||
| 79 | 79 | // release asset get writes an asset. The web's /archive route is the |
| 80 | 80 | // same bytes with a Content-Disposition on them. |
| 81 | 81 | func runRepoDownload(c *Ctx, args []string) int { |
| 82 | const usage = "repo download <owner/name> [--ref <r>] > repo.tar.gz" | |
| 83 | f, err := parseFlags(args, flagSpec{Values: []string{"--ref"}, MaxPos: -1, Usage: usage}) | |
| 82 | f, err := parseFlags(args, flagSpec{Values: []string{"--ref"}, MaxPos: -1, Usage: c.Cmd.Usage}) | |
| 84 | 83 | if err != nil { |
| 85 | 84 | return c.fail(protocol.ExitUsage, "%v", err) |
| 86 | 85 | } |
| 87 | 86 | rest, ref := f.Pos, f.Value("--ref") |
| 88 | 87 | if len(rest) != 1 { |
| 89 | return c.fail(protocol.ExitUsage, "usage: %s", usage) | |
| 88 | return c.usage() | |
| 90 | 89 | } |
| 91 | 90 | repo, code := resolveRepo(c, rest[0], policy.CanRead) |
| 92 | 91 | if code >= 0 { |
internal/control/ghimport.go +1 −1
| @@ -149,7 +149,7 @@ func runImportIssues(c *Ctx, args []string) int { | ||
| 149 | 149 | } |
| 150 | 150 | path, from, apiBase, tokenStdin := f.pos(0), f.Value("--from"), f.Value("--api-base"), f.Has("--token-stdin") |
| 151 | 151 | if path == "" || from == "" { |
| 152 | return c.fail(protocol.ExitUsage, "usage: repo import-issues <owner/name> --from <owner/repo> [--token-stdin] [--api-base <url>]") | |
| 152 | return c.usage() | |
| 153 | 153 | } |
| 154 | 154 | if apiBase == "" { |
| 155 | 155 | apiBase = "https://api.github.com" |
internal/control/identity.go +4 −4
| @@ -51,7 +51,7 @@ func init() { | ||
| 51 | 51 | |
| 52 | 52 | func runWhoami(c *Ctx, args []string) int { |
| 53 | 53 | if len(args) != 0 { |
| 54 | return c.fail(protocol.ExitUsage, "usage: whoami [--json]") | |
| 54 | return c.usage() | |
| 55 | 55 | } |
| 56 | 56 | type out struct { |
| 57 | 57 | Username string `json:"username"` |
| @@ -66,7 +66,7 @@ func runWhoami(c *Ctx, args []string) int { | ||
| 66 | 66 | |
| 67 | 67 | func runKeysList(c *Ctx, args []string) int { |
| 68 | 68 | if len(args) != 0 { |
| 69 | return c.fail(protocol.ExitUsage, "usage: keys list [--json]") | |
| 69 | return c.usage() | |
| 70 | 70 | } |
| 71 | 71 | keys, err := c.Store.ListSSHKeys(c.User.ID) |
| 72 | 72 | if err != nil { |
| @@ -161,7 +161,7 @@ func runKeysAdd(c *Ctx, args []string) int { | ||
| 161 | 161 | |
| 162 | 162 | func runKeysLabel(c *Ctx, args []string) int { |
| 163 | 163 | if len(args) < 1 || len(args) > 2 { |
| 164 | return c.fail(protocol.ExitUsage, "usage: keys label <fingerprint> [<text>]") | |
| 164 | return c.usage() | |
| 165 | 165 | } |
| 166 | 166 | label := "" |
| 167 | 167 | if len(args) == 2 { |
| @@ -189,7 +189,7 @@ func runKeysLabel(c *Ctx, args []string) int { | ||
| 189 | 189 | |
| 190 | 190 | func runKeysRemove(c *Ctx, args []string) int { |
| 191 | 191 | if len(args) != 1 { |
| 192 | return c.fail(protocol.ExitUsage, "usage: keys remove <fingerprint>") | |
| 192 | return c.usage() | |
| 193 | 193 | } |
| 194 | 194 | if err := c.Store.RemoveSSHKey(c.User.ID, args[0]); err != nil { |
| 195 | 195 | if errors.Is(err, store.ErrNotFound) { |
internal/control/import.go +2 −2
| @@ -40,11 +40,11 @@ func runRepoImport(c *Ctx, args []string) int { | ||
| 40 | 40 | } |
| 41 | 41 | path, from, private, tokenStdin := f.pos(0), f.Value("--from"), f.Has("--private"), f.Has("--token-stdin") |
| 42 | 42 | if path == "" || from == "" { |
| 43 | return c.fail(protocol.ExitUsage, "usage: repo import <owner/name> --from <url> [--private] [--token-stdin]") | |
| 43 | return c.usage() | |
| 44 | 44 | } |
| 45 | 45 | owner, name, ok := strings.Cut(path, "/") |
| 46 | 46 | if !ok { |
| 47 | return c.fail(protocol.ExitUsage, "usage: repo import <owner/name> --from <url>") | |
| 47 | return c.usage() | |
| 48 | 48 | } |
| 49 | 49 | if err := policy.ValidateName(name); err != nil { |
| 50 | 50 | return c.failInput(err) |
internal/control/issue.go +8 −9
| @@ -123,7 +123,7 @@ func runIssueCreate(c *Ctx, args []string) int { | ||
| 123 | 123 | } |
| 124 | 124 | path, title, body, file, format := f.pos(0), f.Value("--title"), f.Value("--body"), f.Value("--file"), f.Value("--format") |
| 125 | 125 | if path == "" || title == "" { |
| 126 | return c.fail(protocol.ExitUsage, "usage: issue create <owner/name> --title <t> [--body <b> | --file -] [--format md|org]") | |
| 126 | return c.usage() | |
| 127 | 127 | } |
| 128 | 128 | fmtName, err := markupFormat(format) |
| 129 | 129 | if err != nil { |
| @@ -168,9 +168,8 @@ func runIssueList(c *Ctx, args []string) int { | ||
| 168 | 168 | if code >= 0 { |
| 169 | 169 | return code |
| 170 | 170 | } |
| 171 | const usage = "usage: issue list <owner/name> [--state open|closed|all] [--label <l>] [--assignee <user>] [--author <user>] [--milestone <title>|none] [--search <text>] [--limit <n>] [--cursor <c>]" | |
| 172 | 171 | f := store.IssueFilter{State: "open"} |
| 173 | fl, err := parseFlags(args, flagSpec{Values: []string{"--state", "--label", "--assignee", "--author", "--milestone", "--search"}, MaxPos: 1, Usage: usage}) | |
| 172 | fl, err := parseFlags(args, flagSpec{Values: []string{"--state", "--label", "--assignee", "--author", "--milestone", "--search"}, MaxPos: 1, Usage: c.Cmd.Usage}) | |
| 174 | 173 | if err != nil { |
| 175 | 174 | return c.fail(protocol.ExitUsage, "%v", err) |
| 176 | 175 | } |
| @@ -186,7 +185,7 @@ func runIssueList(c *Ctx, args []string) int { | ||
| 186 | 185 | } |
| 187 | 186 | } |
| 188 | 187 | if path == "" || (f.State != "open" && f.State != "closed" && f.State != "all") { |
| 189 | return c.fail(protocol.ExitUsage, usage) | |
| 188 | return c.usage() | |
| 190 | 189 | } |
| 191 | 190 | repo, code := resolveRepo(c, path, policy.CanRead) |
| 192 | 191 | if code >= 0 { |
| @@ -217,7 +216,7 @@ func runIssueShow(c *Ctx, args []string) int { | ||
| 217 | 216 | return code |
| 218 | 217 | } |
| 219 | 218 | if len(args) != 2 { |
| 220 | return c.fail(protocol.ExitUsage, "usage: issue show <owner/name> <n>") | |
| 219 | return c.usage() | |
| 221 | 220 | } |
| 222 | 221 | comments, err := c.Store.ListIssueComments(issue.ID) |
| 223 | 222 | if err != nil { |
| @@ -265,7 +264,7 @@ func setIssueState(c *Ctx, args []string, state string) int { | ||
| 265 | 264 | return code |
| 266 | 265 | } |
| 267 | 266 | if len(args) != 2 { |
| 268 | return c.fail(protocol.ExitUsage, "usage: issue %s <owner/name> <n>", state) | |
| 267 | return c.usage() | |
| 269 | 268 | } |
| 270 | 269 | if code := authorOrWrite(c, repo, issue.Author, map[string]string{"open": "reopen", "closed": "close"}[state]+" this issue"); code >= 0 { |
| 271 | 270 | return code |
| @@ -312,7 +311,7 @@ func editText(c *Ctx, args []string, kind string) (rest []string, title, body, f | ||
| 312 | 311 | return nil, nil, nil, nil, c.failInput(err) |
| 313 | 312 | } |
| 314 | 313 | if !haveTitle && !haveBody && fmtName == "" { |
| 315 | return nil, nil, nil, nil, c.fail(protocol.ExitUsage, "usage: %s edit <owner/name> <n> [--title <t>] [--body <b> | --file -] [--format md|org]", kind) | |
| 314 | return nil, nil, nil, nil, c.usage() | |
| 316 | 315 | } |
| 317 | 316 | if haveTitle { |
| 318 | 317 | if strings.TrimSpace(titleV) == "" { |
| @@ -378,7 +377,7 @@ func runIssueLabel(c *Ctx, args []string) int { | ||
| 378 | 377 | return c.failInput(err) |
| 379 | 378 | } |
| 380 | 379 | if len(adds)+len(removes) == 0 { |
| 381 | return c.fail(protocol.ExitUsage, "usage: issue label <owner/name> <n> [--add <l>]... [--remove <l>]...") | |
| 380 | return c.usage() | |
| 382 | 381 | } |
| 383 | 382 | repo, issue, code := issueRef(c, rest, policy.CanWrite) |
| 384 | 383 | if code >= 0 { |
| @@ -417,7 +416,7 @@ func runIssueAssign(c *Ctx, args []string) int { | ||
| 417 | 416 | return c.failInput(err) |
| 418 | 417 | } |
| 419 | 418 | if len(adds)+len(removes) == 0 { |
| 420 | return c.fail(protocol.ExitUsage, "usage: issue assign <owner/name> <n> [--add <user>]... [--remove <user>]...") | |
| 419 | return c.usage() | |
| 421 | 420 | } |
| 422 | 421 | repo, issue, code := issueRef(c, rest, policy.CanWrite) |
| 423 | 422 | if code >= 0 { |
internal/control/label.go +4 −5
| @@ -31,7 +31,7 @@ var labelColorPat = regexp.MustCompile(`^#?[0-9a-fA-F]{6}$`) | ||
| 31 | 31 | |
| 32 | 32 | func runLabelList(c *Ctx, args []string) int { |
| 33 | 33 | if len(args) != 1 { |
| 34 | return c.fail(protocol.ExitUsage, "usage: label list <owner/name>") | |
| 34 | return c.usage() | |
| 35 | 35 | } |
| 36 | 36 | repo, code := resolveRepo(c, args[0], policy.CanRead) |
| 37 | 37 | if code >= 0 { |
| @@ -53,15 +53,14 @@ func runLabelList(c *Ctx, args []string) int { | ||
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | func runLabelSet(c *Ctx, args []string) int { |
| 56 | const usage = "usage: label set <owner/name> <label> [--color #rrggbb|'']" | |
| 57 | f, err := parseFlags(args, flagSpec{Values: []string{"--color"}, MaxPos: -1, Usage: usage}) | |
| 56 | f, err := parseFlags(args, flagSpec{Values: []string{"--color"}, MaxPos: -1, Usage: c.Cmd.Usage}) | |
| 58 | 57 | if err != nil { |
| 59 | 58 | return c.fail(protocol.ExitUsage, "%v", err) |
| 60 | 59 | } |
| 61 | 60 | rest := f.Pos |
| 62 | 61 | color, colorSet := strings.ToLower(f.Value("--color")), f.Has("--color") |
| 63 | 62 | if len(rest) != 2 { |
| 64 | return c.fail(protocol.ExitUsage, usage) | |
| 63 | return c.usage() | |
| 65 | 64 | } |
| 66 | 65 | if colorSet && color != "" { |
| 67 | 66 | if !labelColorPat.MatchString(color) { |
| @@ -103,7 +102,7 @@ func runLabelSet(c *Ctx, args []string) int { | ||
| 103 | 102 | |
| 104 | 103 | func runLabelRemove(c *Ctx, args []string) int { |
| 105 | 104 | if len(args) != 2 { |
| 106 | return c.fail(protocol.ExitUsage, "usage: label remove <owner/name> <label>") | |
| 105 | return c.usage() | |
| 107 | 106 | } |
| 108 | 107 | repo, code := resolveRepo(c, args[0], policy.CanWrite) |
| 109 | 108 | if code >= 0 { |
internal/control/migrate.go +1 −1
| @@ -81,7 +81,7 @@ type bundle struct { | ||
| 81 | 81 | |
| 82 | 82 | func runAccountExport(c *Ctx, args []string) int { |
| 83 | 83 | if len(args) != 0 { |
| 84 | return c.fail(protocol.ExitUsage, "usage: account export > bundle.json") | |
| 84 | return c.usage() | |
| 85 | 85 | } |
| 86 | 86 | b := bundle{Bundle: bundleVersion, Username: c.User.Username} |
| 87 | 87 | b.Profile, _ = c.Store.OwnerProfile("user", c.User.ID) |
internal/control/milestone.go +6 −6
| @@ -48,7 +48,7 @@ func runMilestoneCreate(c *Ctx, args []string) int { | ||
| 48 | 48 | } |
| 49 | 49 | path, title, description, due := f.pos(0), f.pos(1), f.Value("--description"), f.Value("--due") |
| 50 | 50 | if path == "" || title == "" { |
| 51 | return c.fail(protocol.ExitUsage, "usage: milestone create <owner/name> <title> [--description <d>] [--due YYYY-MM-DD]") | |
| 51 | return c.usage() | |
| 52 | 52 | } |
| 53 | 53 | if due != "" && !duePat.MatchString(due) { |
| 54 | 54 | return c.fail(protocol.ExitUsage, "--due must be YYYY-MM-DD") |
| @@ -81,7 +81,7 @@ func runMilestoneList(c *Ctx, args []string) int { | ||
| 81 | 81 | state = f.Value("--state") |
| 82 | 82 | } |
| 83 | 83 | if path == "" || (state != "open" && state != "closed" && state != "all") { |
| 84 | return c.fail(protocol.ExitUsage, "usage: milestone list <owner/name> [--state open|closed|all]") | |
| 84 | return c.usage() | |
| 85 | 85 | } |
| 86 | 86 | repo, code := resolveRepo(c, path, policy.CanRead) |
| 87 | 87 | if code >= 0 { |
| @@ -137,7 +137,7 @@ func setMilestoneState(c *Ctx, args []string, state string) int { | ||
| 137 | 137 | verb = "reopen" |
| 138 | 138 | } |
| 139 | 139 | if len(args) != 2 { |
| 140 | return c.fail(protocol.ExitUsage, "usage: milestone %s <owner/name> <title>", verb) | |
| 140 | return c.usage() | |
| 141 | 141 | } |
| 142 | 142 | repo, code := resolveRepo(c, args[0], policy.CanWrite) |
| 143 | 143 | if code >= 0 { |
| @@ -177,7 +177,7 @@ func runIssueMilestone(c *Ctx, args []string) int { | ||
| 177 | 177 | return code |
| 178 | 178 | } |
| 179 | 179 | if len(args) != 3 { |
| 180 | return c.fail(protocol.ExitUsage, "usage: issue milestone <owner/name> <n> <title|none>") | |
| 180 | return c.usage() | |
| 181 | 181 | } |
| 182 | 182 | return setItemMilestone(c, repo, "issue", issue.Number, args[2], func(id int64) error { |
| 183 | 183 | return c.Store.SetIssueMilestone(issue.ID, id) |
| @@ -193,7 +193,7 @@ func runMRMilestone(c *Ctx, args []string) int { | ||
| 193 | 193 | return code |
| 194 | 194 | } |
| 195 | 195 | if len(args) != 3 { |
| 196 | return c.fail(protocol.ExitUsage, "usage: mr milestone <owner/name> <n> <title|none>") | |
| 196 | return c.usage() | |
| 197 | 197 | } |
| 198 | 198 | return setItemMilestone(c, repo, "mr", mr.Number, args[2], func(id int64) error { |
| 199 | 199 | return c.Store.SetMRMilestone(mr.ID, id) |
| @@ -232,7 +232,7 @@ func setItemMilestone(c *Ctx, repo store.Repo, noun string, number int64, title | ||
| 232 | 232 | // runIssueTemplates lists .gitbay/issue-template*.md at the default branch. |
| 233 | 233 | func runIssueTemplates(c *Ctx, args []string) int { |
| 234 | 234 | if len(args) != 1 { |
| 235 | return c.fail(protocol.ExitUsage, "usage: issue templates <owner/name>") | |
| 235 | return c.usage() | |
| 236 | 236 | } |
| 237 | 237 | repo, code := resolveRepo(c, args[0], policy.CanRead) |
| 238 | 238 | if code >= 0 { |
internal/control/mirrorcmd.go +4 −4
| @@ -39,7 +39,7 @@ func runMirrorAdd(c *Ctx, args []string) int { | ||
| 39 | 39 | path, urlArg := f.pos(0), f.pos(1) |
| 40 | 40 | direction, username, tokenStdin := f.Value("--direction"), f.Value("--username"), f.Has("--token-stdin") |
| 41 | 41 | if path == "" || urlArg == "" || (direction != "push" && direction != "pull") { |
| 42 | return c.fail(protocol.ExitUsage, "usage: repo mirror add <owner/name> <https-url> --direction push|pull [--username <u>] [--token-stdin]") | |
| 42 | return c.usage() | |
| 43 | 43 | } |
| 44 | 44 | // The worker's git process dials this URL from the server: same SSRF |
| 45 | 45 | // surface as a webhook target, same rules. |
| @@ -76,7 +76,7 @@ func runMirrorAdd(c *Ctx, args []string) int { | ||
| 76 | 76 | |
| 77 | 77 | func runMirrorList(c *Ctx, args []string) int { |
| 78 | 78 | if len(args) != 1 { |
| 79 | return c.fail(protocol.ExitUsage, "usage: repo mirror list <owner/name>") | |
| 79 | return c.usage() | |
| 80 | 80 | } |
| 81 | 81 | repo, code := resolveRepo(c, args[0], policy.CanAdmin) |
| 82 | 82 | if code >= 0 { |
| @@ -123,7 +123,7 @@ func orDash(s string) string { | ||
| 123 | 123 | |
| 124 | 124 | func runMirrorRemove(c *Ctx, args []string) int { |
| 125 | 125 | if len(args) != 2 { |
| 126 | return c.fail(protocol.ExitUsage, "usage: repo mirror remove <owner/name> <id>") | |
| 126 | return c.usage() | |
| 127 | 127 | } |
| 128 | 128 | repo, code := resolveRepo(c, args[0], policy.CanAdmin) |
| 129 | 129 | if code >= 0 { |
| @@ -146,7 +146,7 @@ func runMirrorRemove(c *Ctx, args []string) int { | ||
| 146 | 146 | |
| 147 | 147 | func runMirrorSync(c *Ctx, args []string) int { |
| 148 | 148 | if len(args) != 1 { |
| 149 | return c.fail(protocol.ExitUsage, "usage: repo mirror sync <owner/name>") | |
| 149 | return c.usage() | |
| 150 | 150 | } |
| 151 | 151 | repo, code := resolveRepo(c, args[0], policy.CanAdmin) |
| 152 | 152 | if code >= 0 { |
internal/control/mr.go +19 −26
| @@ -104,7 +104,7 @@ func runRepoFork(c *Ctx, args []string) int { | ||
| 104 | 104 | } |
| 105 | 105 | path, name := f.pos(0), f.Value("--name") |
| 106 | 106 | if path == "" { |
| 107 | return c.fail(protocol.ExitUsage, "usage: repo fork <owner/name> [--name <n>]") | |
| 107 | return c.usage() | |
| 108 | 108 | } |
| 109 | 109 | src, code := resolveRepo(c, path, policy.CanRead) |
| 110 | 110 | if code >= 0 { |
| @@ -150,7 +150,7 @@ func runRepoFork(c *Ctx, args []string) int { | ||
| 150 | 150 | |
| 151 | 151 | func runRequireApprovals(c *Ctx, args []string) int { |
| 152 | 152 | if len(args) != 2 { |
| 153 | return c.fail(protocol.ExitUsage, "usage: repo settings require-approvals <owner/name> <n>") | |
| 153 | return c.usage() | |
| 154 | 154 | } |
| 155 | 155 | n, err := strconv.Atoi(args[1]) |
| 156 | 156 | if err != nil || n < 0 || n > 20 { |
| @@ -171,7 +171,7 @@ func runRequireApprovals(c *Ctx, args []string) int { | ||
| 171 | 171 | |
| 172 | 172 | func runRequireResolved(c *Ctx, args []string) int { |
| 173 | 173 | if len(args) != 2 || (args[1] != "on" && args[1] != "off") { |
| 174 | return c.fail(protocol.ExitUsage, "usage: repo settings require-resolved <owner/name> on|off") | |
| 174 | return c.usage() | |
| 175 | 175 | } |
| 176 | 176 | repo, code := resolveRepo(c, args[0], policy.CanAdmin) |
| 177 | 177 | if code >= 0 { |
| @@ -188,7 +188,7 @@ func runRequireResolved(c *Ctx, args []string) int { | ||
| 188 | 188 | |
| 189 | 189 | func runRequireCodeowners(c *Ctx, args []string) int { |
| 190 | 190 | if len(args) != 2 || (args[1] != "on" && args[1] != "off") { |
| 191 | return c.fail(protocol.ExitUsage, "usage: repo settings require-codeowners <owner/name> on|off") | |
| 191 | return c.usage() | |
| 192 | 192 | } |
| 193 | 193 | repo, code := resolveRepo(c, args[0], policy.CanAdmin) |
| 194 | 194 | if code >= 0 { |
| @@ -205,7 +205,7 @@ func runRequireCodeowners(c *Ctx, args []string) int { | ||
| 205 | 205 | |
| 206 | 206 | func runRequireChecks(c *Ctx, args []string) int { |
| 207 | 207 | if len(args) != 2 || (args[1] != "on" && args[1] != "off") { |
| 208 | return c.fail(protocol.ExitUsage, "usage: repo settings require-checks <owner/name> on|off") | |
| 208 | return c.usage() | |
| 209 | 209 | } |
| 210 | 210 | repo, code := resolveRepo(c, args[0], policy.CanAdmin) |
| 211 | 211 | if code >= 0 { |
| @@ -222,7 +222,7 @@ func runRequireChecks(c *Ctx, args []string) int { | ||
| 222 | 222 | |
| 223 | 223 | func runRequireMR(c *Ctx, args []string) int { |
| 224 | 224 | if len(args) != 2 || (args[1] != "on" && args[1] != "off") { |
| 225 | return c.fail(protocol.ExitUsage, "usage: repo settings require-mr <owner/name> on|off") | |
| 225 | return c.usage() | |
| 226 | 226 | } |
| 227 | 227 | repo, code := resolveRepo(c, args[0], policy.CanAdmin) |
| 228 | 228 | if code >= 0 { |
| @@ -239,7 +239,7 @@ func runRequireMR(c *Ctx, args []string) int { | ||
| 239 | 239 | |
| 240 | 240 | func runRequireSigned(c *Ctx, args []string) int { |
| 241 | 241 | if len(args) != 2 || (args[1] != "on" && args[1] != "off") { |
| 242 | return c.fail(protocol.ExitUsage, "usage: repo settings require-signed <owner/name> on|off") | |
| 242 | return c.usage() | |
| 243 | 243 | } |
| 244 | 244 | repo, code := resolveRepo(c, args[0], policy.CanAdmin) |
| 245 | 245 | if code >= 0 { |
| @@ -282,7 +282,7 @@ func runMRCreate(c *Ctx, args []string) int { | ||
| 282 | 282 | path, source, target := f.pos(0), f.Value("--source"), f.Value("--target") |
| 283 | 283 | title, body, file, format := f.Value("--title"), f.Value("--body"), f.Value("--file"), f.Value("--format") |
| 284 | 284 | if path == "" || source == "" || title == "" { |
| 285 | return c.fail(protocol.ExitUsage, "usage: mr create <target owner/name> --source [owner/name:]<branch> --target <branch> --title <t> [--draft]") | |
| 285 | return c.usage() | |
| 286 | 286 | } |
| 287 | 287 | fmtName, err := markupFormat(format) |
| 288 | 288 | if err != nil { |
| @@ -441,9 +441,8 @@ func runMRList(c *Ctx, args []string) int { | ||
| 441 | 441 | if code >= 0 { |
| 442 | 442 | return code |
| 443 | 443 | } |
| 444 | const usage = "usage: mr list <owner/name> [--state open|merged|closed|source_gone|all] [--author <user>] [--milestone <title>|none] [--search <text>] [--limit <n>] [--cursor <c>]" | |
| 445 | 444 | f := store.MRFilter{State: "open"} |
| 446 | fl, err := parseFlags(args, flagSpec{Values: []string{"--state", "--author", "--milestone", "--search"}, MaxPos: 1, Usage: usage}) | |
| 445 | fl, err := parseFlags(args, flagSpec{Values: []string{"--state", "--author", "--milestone", "--search"}, MaxPos: 1, Usage: c.Cmd.Usage}) | |
| 447 | 446 | if err != nil { |
| 448 | 447 | return c.fail(protocol.ExitUsage, "%v", err) |
| 449 | 448 | } |
| @@ -460,7 +459,7 @@ func runMRList(c *Ctx, args []string) int { | ||
| 460 | 459 | } |
| 461 | 460 | valid := map[string]bool{"open": true, "merged": true, "closed": true, "source_gone": true, "all": true} |
| 462 | 461 | if path == "" || !valid[f.State] { |
| 463 | return c.fail(protocol.ExitUsage, usage) | |
| 462 | return c.usage() | |
| 464 | 463 | } |
| 465 | 464 | repo, code := resolveRepo(c, path, policy.CanRead) |
| 466 | 465 | if code >= 0 { |
| @@ -510,7 +509,7 @@ func runMRShow(c *Ctx, args []string) int { | ||
| 510 | 509 | return code |
| 511 | 510 | } |
| 512 | 511 | if len(args) != 2 { |
| 513 | return c.fail(protocol.ExitUsage, "usage: mr show <owner/name> <n>") | |
| 512 | return c.usage() | |
| 514 | 513 | } |
| 515 | 514 | comments, err := c.Store.ListMRComments(mr.ID) |
| 516 | 515 | if err != nil { |
| @@ -701,7 +700,7 @@ func runMREdit(c *Ctx, args []string) int { | ||
| 701 | 700 | // same repository. |
| 702 | 701 | func runMRRetarget(c *Ctx, args []string) int { |
| 703 | 702 | if len(args) != 3 { |
| 704 | return c.fail(protocol.ExitUsage, "usage: mr retarget <owner/name> <n> <branch>") | |
| 703 | return c.usage() | |
| 705 | 704 | } |
| 706 | 705 | repo, mr, code := mrRef(c, args[:2], policy.CanRead) |
| 707 | 706 | if code >= 0 { |
| @@ -779,12 +778,11 @@ func runMRReview(c *Ctx, args []string) int { | ||
| 779 | 778 | rest = append(rest, a) |
| 780 | 779 | } |
| 781 | 780 | } |
| 782 | const usage = "mr review <owner/name> <n> --approve|--request-changes|--comment|--discard" | |
| 783 | 781 | if discard && verdict != "" { |
| 784 | 782 | return c.fail(protocol.ExitUsage, "--discard throws the batch away; it takes no verdict") |
| 785 | 783 | } |
| 786 | 784 | if verdict == "" && !discard { |
| 787 | return c.fail(protocol.ExitUsage, "usage: %s", usage) | |
| 785 | return c.usage() | |
| 788 | 786 | } |
| 789 | 787 | repo, mr, code := mrRef(c, rest, policy.CanRead) |
| 790 | 788 | if code >= 0 { |
| @@ -848,7 +846,7 @@ func runMRReviewRequest(c *Ctx, args []string) int { | ||
| 848 | 846 | return c.failInput(err) |
| 849 | 847 | } |
| 850 | 848 | if len(adds)+len(removes) == 0 { |
| 851 | return c.fail(protocol.ExitUsage, "usage: mr review request <owner/name> <n> [--add <user>]... [--remove <user>]...") | |
| 849 | return c.usage() | |
| 852 | 850 | } |
| 853 | 851 | repo, mr, code := mrRef(c, rest, policy.CanWrite) |
| 854 | 852 | if code >= 0 { |
| @@ -1404,10 +1402,6 @@ func runMRDraft(c *Ctx, args []string) int { return setMRDraft(c, args, true) } | ||
| 1404 | 1402 | func runMRReady(c *Ctx, args []string) int { return setMRDraft(c, args, false) } |
| 1405 | 1403 | |
| 1406 | 1404 | func setMRDraft(c *Ctx, args []string, draft bool) int { |
| 1407 | verb := "ready" | |
| 1408 | if draft { | |
| 1409 | verb = "draft" | |
| 1410 | } | |
| 1411 | 1405 | repo, mr, code := mrRef(c, args, policy.CanRead) |
| 1412 | 1406 | if code >= 0 { |
| 1413 | 1407 | return code |
| @@ -1416,7 +1410,7 @@ func setMRDraft(c *Ctx, args []string, draft bool) int { | ||
| 1416 | 1410 | return code |
| 1417 | 1411 | } |
| 1418 | 1412 | if len(args) != 2 { |
| 1419 | return c.fail(protocol.ExitUsage, "usage: mr %s <owner/name> <n>", verb) | |
| 1413 | return c.usage() | |
| 1420 | 1414 | } |
| 1421 | 1415 | if code := authorOrWrite(c, repo, mr.Author, "change this merge request"); code >= 0 { |
| 1422 | 1416 | return code |
| @@ -1471,7 +1465,7 @@ func runMRClose(c *Ctx, args []string) int { | ||
| 1471 | 1465 | return code |
| 1472 | 1466 | } |
| 1473 | 1467 | if len(args) != 2 { |
| 1474 | return c.fail(protocol.ExitUsage, "usage: mr close <owner/name> <n>") | |
| 1468 | return c.usage() | |
| 1475 | 1469 | } |
| 1476 | 1470 | if code := authorOrWrite(c, repo, mr.Author, "close this merge request"); code >= 0 { |
| 1477 | 1471 | return code |
| @@ -1532,7 +1526,7 @@ func runMRRevisions(c *Ctx, args []string) int { | ||
| 1532 | 1526 | return code |
| 1533 | 1527 | } |
| 1534 | 1528 | if len(args) != 2 { |
| 1535 | return c.fail(protocol.ExitUsage, "usage: mr revisions <owner/name> <n>") | |
| 1529 | return c.usage() | |
| 1536 | 1530 | } |
| 1537 | 1531 | revs, err := mrRevisions(c, mr) |
| 1538 | 1532 | if err != nil { |
| @@ -1554,8 +1548,7 @@ func runMRRevisions(c *Ctx, args []string) int { | ||
| 1554 | 1548 | } |
| 1555 | 1549 | |
| 1556 | 1550 | func runMRRangeDiff(c *Ctx, args []string) int { |
| 1557 | const usage = "mr range-diff <owner/name> <n> [--from <sha>] [--to <sha>]" | |
| 1558 | f, err := parseFlags(args, flagSpec{Values: []string{"--from", "--to"}, MaxPos: 2, Usage: usage}) | |
| 1551 | f, err := parseFlags(args, flagSpec{Values: []string{"--from", "--to"}, MaxPos: 2, Usage: c.Cmd.Usage}) | |
| 1559 | 1552 | if err != nil { |
| 1560 | 1553 | return c.fail(protocol.ExitUsage, "%v", err) |
| 1561 | 1554 | } |
| @@ -1564,7 +1557,7 @@ func runMRRangeDiff(c *Ctx, args []string) int { | ||
| 1564 | 1557 | return code |
| 1565 | 1558 | } |
| 1566 | 1559 | if len(f.Pos) != 2 { |
| 1567 | return c.fail(protocol.ExitUsage, "usage: %s", usage) | |
| 1560 | return c.usage() | |
| 1568 | 1561 | } |
| 1569 | 1562 | revs, err := mrRevisions(c, mr) |
| 1570 | 1563 | if err != nil { |
internal/control/notifications.go +7 −9
| @@ -168,7 +168,7 @@ func emitNotificationSettings(c *Ctx) int { | ||
| 168 | 168 | |
| 169 | 169 | func runNotificationsSettingsShow(c *Ctx, args []string) int { |
| 170 | 170 | if len(args) != 0 { |
| 171 | return c.fail(protocol.ExitUsage, "usage: notifications settings show") | |
| 171 | return c.usage() | |
| 172 | 172 | } |
| 173 | 173 | return emitNotificationSettings(c) |
| 174 | 174 | } |
| @@ -177,7 +177,7 @@ func runNotificationsSettingsShow(c *Ctx, args []string) int { | ||
| 177 | 177 | // inbox is filed either way, the mail half consults it (#194). |
| 178 | 178 | func runNotificationsSettingsMail(c *Ctx, args []string) int { |
| 179 | 179 | if len(args) != 1 || (args[0] != "on" && args[0] != "off") { |
| 180 | return c.fail(protocol.ExitUsage, "usage: notifications settings mail on|off") | |
| 180 | return c.usage() | |
| 181 | 181 | } |
| 182 | 182 | if err := c.Store.SetMailEnabled(c.User.ID, args[0] == "on"); err != nil { |
| 183 | 183 | return c.fail(protocol.ExitFailure, "%v", err) |
| @@ -190,7 +190,7 @@ func runNotificationsSettingsMail(c *Ctx, args []string) int { | ||
| 190 | 190 | // delivered, so a grant or a revoke needs no watch row of its own (#194). |
| 191 | 191 | func runNotificationsSettingsWatch(c *Ctx, args []string) int { |
| 192 | 192 | if len(args) != 1 || (args[0] != "on" && args[0] != "off") { |
| 193 | return c.fail(protocol.ExitUsage, "usage: notifications settings watch on|off") | |
| 193 | return c.usage() | |
| 194 | 194 | } |
| 195 | 195 | if err := c.Store.SetWatchEnabled(c.User.ID, args[0] == "on"); err != nil { |
| 196 | 196 | return c.fail(protocol.ExitFailure, "%v", err) |
| @@ -202,12 +202,11 @@ func runNotificationsSettingsWatch(c *Ctx, args []string) int { | ||
| 202 | 202 | const noticesDefaultLimit = 50 |
| 203 | 203 | |
| 204 | 204 | func runNotificationsList(c *Ctx, args []string) int { |
| 205 | const usage = "notifications list [--all] [--limit <n>] [--cursor <c>]" | |
| 206 | 205 | rest, p, code := parsePageFlags(c, args, "notifications", true) |
| 207 | 206 | if code >= 0 { |
| 208 | 207 | return code |
| 209 | 208 | } |
| 210 | fl, err := parseFlags(rest, flagSpec{Bools: []string{"--all"}, Usage: usage}) | |
| 209 | fl, err := parseFlags(rest, flagSpec{Bools: []string{"--all"}, Usage: c.Cmd.Usage}) | |
| 211 | 210 | if err != nil { |
| 212 | 211 | return c.fail(protocol.ExitUsage, "%v", err) |
| 213 | 212 | } |
| @@ -249,15 +248,14 @@ func runNotificationsList(c *Ctx, args []string) int { | ||
| 249 | 248 | } |
| 250 | 249 | |
| 251 | 250 | func runNotificationsRead(c *Ctx, args []string) int { |
| 252 | const usage = "notifications read <id>... | --all" | |
| 253 | fl, err := parseFlags(args, flagSpec{Bools: []string{"--all"}, MaxPos: -1, Usage: usage}) | |
| 251 | fl, err := parseFlags(args, flagSpec{Bools: []string{"--all"}, MaxPos: -1, Usage: c.Cmd.Usage}) | |
| 254 | 252 | if err != nil { |
| 255 | 253 | return c.fail(protocol.ExitUsage, "%v", err) |
| 256 | 254 | } |
| 257 | 255 | // --all and a list of ids are two ways of saying which rows: taking |
| 258 | 256 | // both would leave which one won unstated. |
| 259 | 257 | if fl.Has("--all") == (len(fl.Pos) > 0) { |
| 260 | return c.fail(protocol.ExitUsage, "usage: %s", usage) | |
| 258 | return c.usage() | |
| 261 | 259 | } |
| 262 | 260 | var ids []int64 |
| 263 | 261 | for _, a := range fl.Pos { |
| @@ -285,7 +283,7 @@ func runRepoUnwatch(c *Ctx, args []string) int { return setWatch(c, args, "unwat | ||
| 285 | 283 | // same way. |
| 286 | 284 | func setWatch(c *Ctx, args []string, verb, state string) int { |
| 287 | 285 | if len(args) != 1 { |
| 288 | return c.fail(protocol.ExitUsage, "usage: repo %s <owner/name>", verb) | |
| 286 | return c.usage() | |
| 289 | 287 | } |
| 290 | 288 | repo, code := resolveRepo(c, args[0], policy.CanRead) |
| 291 | 289 | if code >= 0 { |
internal/control/org.go +8 −8
| @@ -60,7 +60,7 @@ func orgAdmin(c *Ctx, name string) (store.Org, int) { | ||
| 60 | 60 | |
| 61 | 61 | func runOrgCreate(c *Ctx, args []string) int { |
| 62 | 62 | if len(args) != 1 { |
| 63 | return c.fail(protocol.ExitUsage, "usage: org create <name>") | |
| 63 | return c.usage() | |
| 64 | 64 | } |
| 65 | 65 | if err := policy.ValidateOwnerName(args[0]); err != nil { |
| 66 | 66 | return c.failInput(err) |
| @@ -95,7 +95,7 @@ func runOrgList(c *Ctx, args []string) int { | ||
| 95 | 95 | |
| 96 | 96 | func runOrgShow(c *Ctx, args []string) int { |
| 97 | 97 | if len(args) != 1 { |
| 98 | return c.fail(protocol.ExitUsage, "usage: org show <name>") | |
| 98 | return c.usage() | |
| 99 | 99 | } |
| 100 | 100 | org, err := c.Store.OrgByName(args[0]) |
| 101 | 101 | if errors.Is(err, store.ErrNotFound) { |
| @@ -130,7 +130,7 @@ func runOrgShow(c *Ctx, args []string) int { | ||
| 130 | 130 | |
| 131 | 131 | func runOrgRename(c *Ctx, args []string) int { |
| 132 | 132 | if len(args) != 2 { |
| 133 | return c.fail(protocol.ExitUsage, "usage: org rename <old> <new>") | |
| 133 | return c.usage() | |
| 134 | 134 | } |
| 135 | 135 | org, code := orgAdmin(c, args[0]) |
| 136 | 136 | if code >= 0 { |
| @@ -170,11 +170,11 @@ func runOrgDelete(c *Ctx, args []string) int { | ||
| 170 | 170 | } else if name == "" { |
| 171 | 171 | name = a |
| 172 | 172 | } else { |
| 173 | return c.fail(protocol.ExitUsage, "usage: org delete <name> --yes") | |
| 173 | return c.usage() | |
| 174 | 174 | } |
| 175 | 175 | } |
| 176 | 176 | if name == "" { |
| 177 | return c.fail(protocol.ExitUsage, "usage: org delete <name> --yes") | |
| 177 | return c.usage() | |
| 178 | 178 | } |
| 179 | 179 | org, code := orgAdmin(c, name) |
| 180 | 180 | if code >= 0 { |
| @@ -201,7 +201,7 @@ func runOrgMembersAdd(c *Ctx, args []string) int { | ||
| 201 | 201 | role = f.Value("--role") |
| 202 | 202 | } |
| 203 | 203 | if len(rest) != 2 || (role != "member" && role != "admin") { |
| 204 | return c.fail(protocol.ExitUsage, "usage: org members add <org> <user> [--role member|admin]") | |
| 204 | return c.usage() | |
| 205 | 205 | } |
| 206 | 206 | org, code := orgAdmin(c, rest[0]) |
| 207 | 207 | if code >= 0 { |
| @@ -224,7 +224,7 @@ func runOrgMembersAdd(c *Ctx, args []string) int { | ||
| 224 | 224 | |
| 225 | 225 | func runOrgMembersRemove(c *Ctx, args []string) int { |
| 226 | 226 | if len(args) != 2 { |
| 227 | return c.fail(protocol.ExitUsage, "usage: org members remove <org> <user>") | |
| 227 | return c.usage() | |
| 228 | 228 | } |
| 229 | 229 | org, code := orgAdmin(c, args[0]) |
| 230 | 230 | if code >= 0 { |
| @@ -250,7 +250,7 @@ func runOrgMembersRemove(c *Ctx, args []string) int { | ||
| 250 | 250 | |
| 251 | 251 | func runOrgMembersList(c *Ctx, args []string) int { |
| 252 | 252 | if len(args) != 1 { |
| 253 | return c.fail(protocol.ExitUsage, "usage: org members list <org>") | |
| 253 | return c.usage() | |
| 254 | 254 | } |
| 255 | 255 | return runOrgShow(c, args) |
| 256 | 256 | } |
internal/control/orglabel.go +8 −10
| @@ -62,15 +62,14 @@ func orgReader(c *Ctx, name string) (store.Org, []int64, int) { | ||
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | func runOrgLabelSet(c *Ctx, args []string) int { |
| 65 | const usage = "usage: org label set <org> <label> [--color rrggbb|'']" | |
| 66 | f, err := parseFlags(args, flagSpec{Values: []string{"--color"}, MaxPos: 2, Usage: usage}) | |
| 65 | f, err := parseFlags(args, flagSpec{Values: []string{"--color"}, MaxPos: 2, Usage: c.Cmd.Usage}) | |
| 67 | 66 | if err != nil { |
| 68 | 67 | return c.fail(protocol.ExitUsage, "%v", err) |
| 69 | 68 | } |
| 70 | 69 | orgName, name := f.pos(0), f.pos(1) |
| 71 | 70 | color, colorSet := strings.ToLower(f.Value("--color")), f.Has("--color") |
| 72 | 71 | if orgName == "" || name == "" { |
| 73 | return c.fail(protocol.ExitUsage, usage) | |
| 72 | return c.usage() | |
| 74 | 73 | } |
| 75 | 74 | if name == "" || len(name) > 50 { |
| 76 | 75 | return c.fail(protocol.ExitUsage, "a label is 1 to 50 characters") |
| @@ -118,7 +117,7 @@ func runOrgLabelSet(c *Ctx, args []string) int { | ||
| 118 | 117 | |
| 119 | 118 | func runOrgLabelList(c *Ctx, args []string) int { |
| 120 | 119 | if len(args) != 1 { |
| 121 | return c.fail(protocol.ExitUsage, "usage: org label list <org>") | |
| 120 | return c.usage() | |
| 122 | 121 | } |
| 123 | 122 | org, readable, code := orgReader(c, args[0]) |
| 124 | 123 | if code >= 0 { |
| @@ -137,7 +136,7 @@ func runOrgLabelList(c *Ctx, args []string) int { | ||
| 137 | 136 | |
| 138 | 137 | func runOrgLabelRemove(c *Ctx, args []string) int { |
| 139 | 138 | if len(args) != 2 { |
| 140 | return c.fail(protocol.ExitUsage, "usage: org label remove <org> <label>") | |
| 139 | return c.usage() | |
| 141 | 140 | } |
| 142 | 141 | org, code := orgAdmin(c, args[0]) |
| 143 | 142 | if code >= 0 { |
| @@ -155,14 +154,13 @@ func runOrgLabelRemove(c *Ctx, args []string) int { | ||
| 155 | 154 | } |
| 156 | 155 | |
| 157 | 156 | func runOrgMilestoneCreate(c *Ctx, args []string) int { |
| 158 | const usage = "usage: org milestone create <org> <title> [--description <d>] [--due YYYY-MM-DD]" | |
| 159 | f, err := parseFlags(args, flagSpec{Values: []string{"--description", "--due"}, MaxPos: 2, Usage: usage}) | |
| 157 | f, err := parseFlags(args, flagSpec{Values: []string{"--description", "--due"}, MaxPos: 2, Usage: c.Cmd.Usage}) | |
| 160 | 158 | if err != nil { |
| 161 | 159 | return c.fail(protocol.ExitUsage, "%v", err) |
| 162 | 160 | } |
| 163 | 161 | orgName, title, description, due := f.pos(0), f.pos(1), f.Value("--description"), f.Value("--due") |
| 164 | 162 | if orgName == "" || title == "" { |
| 165 | return c.fail(protocol.ExitUsage, usage) | |
| 163 | return c.usage() | |
| 166 | 164 | } |
| 167 | 165 | if due != "" && !duePat.MatchString(due) { |
| 168 | 166 | return c.fail(protocol.ExitUsage, "--due must be YYYY-MM-DD") |
| @@ -197,7 +195,7 @@ func runOrgMilestoneList(c *Ctx, args []string) int { | ||
| 197 | 195 | state = f.Value("--state") |
| 198 | 196 | } |
| 199 | 197 | if orgName == "" || (state != "open" && state != "closed" && state != "all") { |
| 200 | return c.fail(protocol.ExitUsage, "usage: org milestone list <org> [--state open|closed|all]") | |
| 198 | return c.usage() | |
| 201 | 199 | } |
| 202 | 200 | org, readable, code := orgReader(c, orgName) |
| 203 | 201 | if code >= 0 { |
| @@ -219,7 +217,7 @@ func setOrgMilestoneState(c *Ctx, args []string, state string) int { | ||
| 219 | 217 | verb = "reopen" |
| 220 | 218 | } |
| 221 | 219 | if len(args) != 2 { |
| 222 | return c.fail(protocol.ExitUsage, "usage: org milestone %s <org> <title>", verb) | |
| 220 | return c.usage() | |
| 223 | 221 | } |
| 224 | 222 | org, code := orgAdmin(c, args[0]) |
| 225 | 223 | if code >= 0 { |
internal/control/pagescmd.go +4 −4
| @@ -70,7 +70,7 @@ func challengeRecord(domain, token string) (name, value string) { | ||
| 70 | 70 | |
| 71 | 71 | func runDomainAdd(c *Ctx, args []string) int { |
| 72 | 72 | if len(args) != 2 { |
| 73 | return c.fail(protocol.ExitUsage, "usage: repo domain add <owner/name> <domain>") | |
| 73 | return c.usage() | |
| 74 | 74 | } |
| 75 | 75 | domain := strings.ToLower(args[1]) |
| 76 | 76 | if err := validatePageDomain(c, domain); err != nil { |
| @@ -121,7 +121,7 @@ func lookupTXT(name string) ([]string, error) { | ||
| 121 | 121 | |
| 122 | 122 | func runDomainVerify(c *Ctx, args []string) int { |
| 123 | 123 | if len(args) != 2 { |
| 124 | return c.fail(protocol.ExitUsage, "usage: repo domain verify <owner/name> <domain>") | |
| 124 | return c.usage() | |
| 125 | 125 | } |
| 126 | 126 | repo, code := resolveRepo(c, args[0], policy.CanAdmin) |
| 127 | 127 | if code >= 0 { |
| @@ -167,7 +167,7 @@ func runDomainVerify(c *Ctx, args []string) int { | ||
| 167 | 167 | |
| 168 | 168 | func runDomainRemove(c *Ctx, args []string) int { |
| 169 | 169 | if len(args) != 2 { |
| 170 | return c.fail(protocol.ExitUsage, "usage: repo domain remove <owner/name> <domain>") | |
| 170 | return c.usage() | |
| 171 | 171 | } |
| 172 | 172 | repo, code := resolveRepo(c, args[0], policy.CanAdmin) |
| 173 | 173 | if code >= 0 { |
| @@ -187,7 +187,7 @@ func runDomainRemove(c *Ctx, args []string) int { | ||
| 187 | 187 | |
| 188 | 188 | func runDomainList(c *Ctx, args []string) int { |
| 189 | 189 | if len(args) != 1 { |
| 190 | return c.fail(protocol.ExitUsage, "usage: repo domain list <owner/name>") | |
| 190 | return c.usage() | |
| 191 | 191 | } |
| 192 | 192 | repo, code := resolveRepo(c, args[0], policy.CanRead) |
| 193 | 193 | if code >= 0 { |
internal/control/profile.go +3 −5
| @@ -257,7 +257,7 @@ func runProfileShow(c *Ctx, args []string) int { | ||
| 257 | 257 | if len(args) == 1 { |
| 258 | 258 | name = args[0] |
| 259 | 259 | } else if len(args) > 1 { |
| 260 | return c.fail(protocol.ExitUsage, "usage: profile show [name]") | |
| 260 | return c.usage() | |
| 261 | 261 | } |
| 262 | 262 | kind, id := "", int64(0) |
| 263 | 263 | if u, err := c.Store.UserByUsername(name); err == nil { |
| @@ -360,8 +360,7 @@ func runProfileSet(c *Ctx, args []string) int { | ||
| 360 | 360 | return c.failInput(err) |
| 361 | 361 | } |
| 362 | 362 | if len(rest) != 0 { |
| 363 | return c.fail(protocol.ExitUsage, | |
| 364 | "usage: profile set [--description <d>] [--website <url>] [--about <text>|--file -] [--about-format md|org] [--link <label|url>]...") | |
| 363 | return c.usage() | |
| 365 | 364 | } |
| 366 | 365 | if e.empty() { |
| 367 | 366 | return c.fail(protocol.ExitUsage, "nothing to set: pass --description, --website, --about and/or --link") |
| @@ -388,8 +387,7 @@ func runOrgProfile(c *Ctx, args []string) int { | ||
| 388 | 387 | return c.failInput(err) |
| 389 | 388 | } |
| 390 | 389 | if len(rest) != 1 { |
| 391 | return c.fail(protocol.ExitUsage, | |
| 392 | "usage: org profile <org> [--description <d>] [--website <url>] [--about <text>|--file -] [--about-format md|org] [--link <label|url>]...") | |
| 390 | return c.usage() | |
| 393 | 391 | } |
| 394 | 392 | name := rest[0] |
| 395 | 393 | if e.empty() { |
internal/control/quota.go +2 −2
| @@ -93,7 +93,7 @@ func runAdminUserLimits(c *Ctx, args []string) int { | ||
| 93 | 93 | return code |
| 94 | 94 | } |
| 95 | 95 | if len(args) < 1 { |
| 96 | return c.fail(protocol.ExitUsage, "usage: admin user limits <username> [--repos <n>|default] [--bytes <n>|default]") | |
| 96 | return c.usage() | |
| 97 | 97 | } |
| 98 | 98 | u, err := c.Store.UserByUsername(args[0]) |
| 99 | 99 | if err != nil { |
| @@ -116,7 +116,7 @@ func runAdminUserLimits(c *Ctx, args []string) int { | ||
| 116 | 116 | case "--bytes": |
| 117 | 117 | target = &l.Bytes |
| 118 | 118 | default: |
| 119 | return c.fail(protocol.ExitUsage, "usage: admin user limits <username> [--repos <n>|default] [--bytes <n>|default]") | |
| 119 | return c.usage() | |
| 120 | 120 | } |
| 121 | 121 | if v == "default" { |
| 122 | 122 | *target = nil |
internal/control/read.go +8 −11
| @@ -48,7 +48,7 @@ func init() { | ||
| 48 | 48 | |
| 49 | 49 | func runRepoRefs(c *Ctx, args []string) int { |
| 50 | 50 | if len(args) != 1 { |
| 51 | return c.fail(protocol.ExitUsage, "usage: repo refs <owner/name>") | |
| 51 | return c.usage() | |
| 52 | 52 | } |
| 53 | 53 | repo, code := resolveRepo(c, args[0], policy.CanRead) |
| 54 | 54 | if code >= 0 { |
| @@ -93,8 +93,7 @@ func runRepoRefs(c *Ctx, args []string) int { | ||
| 93 | 93 | const BlameSpan = 1000 |
| 94 | 94 | |
| 95 | 95 | func runRepoBlame(c *Ctx, args []string) int { |
| 96 | const usage = "repo blame <owner/name> <path> [--ref <ref>] [--from <n>] [--to <n>]" | |
| 97 | f, err := parseFlags(args, flagSpec{Values: []string{"--ref", "--from", "--to"}, MaxPos: -1, Usage: usage}) | |
| 96 | f, err := parseFlags(args, flagSpec{Values: []string{"--ref", "--from", "--to"}, MaxPos: -1, Usage: c.Cmd.Usage}) | |
| 98 | 97 | if err != nil { |
| 99 | 98 | return c.fail(protocol.ExitUsage, "%v", err) |
| 100 | 99 | } |
| @@ -111,7 +110,7 @@ func runRepoBlame(c *Ctx, args []string) int { | ||
| 111 | 110 | *dst = n |
| 112 | 111 | } |
| 113 | 112 | if len(rest) != 2 { |
| 114 | return c.fail(protocol.ExitUsage, "usage: %s", usage) | |
| 113 | return c.usage() | |
| 115 | 114 | } |
| 116 | 115 | repo, code := resolveRepo(c, rest[0], policy.CanRead) |
| 117 | 116 | if code >= 0 { |
| @@ -204,7 +203,7 @@ func runRepoBlame(c *Ctx, args []string) int { | ||
| 204 | 203 | // off argv. Positionals are returned in order so each command can name them |
| 205 | 204 | // in its own usage message. |
| 206 | 205 | func readArgs(c *Ctx, args []string, usage string, maxPos int) (pos []string, ref string, code int) { |
| 207 | f, err := parseFlags(args, flagSpec{Values: []string{"--ref"}, MaxPos: maxPos, Usage: usage}) | |
| 206 | f, err := parseFlags(args, flagSpec{Values: []string{"--ref"}, MaxPos: maxPos, Usage: c.Cmd.Usage}) | |
| 208 | 207 | if err != nil { |
| 209 | 208 | return nil, "", c.fail(protocol.ExitUsage, "%v", err) |
| 210 | 209 | } |
| @@ -239,13 +238,12 @@ type entryOut struct { | ||
| 239 | 238 | } |
| 240 | 239 | |
| 241 | 240 | func runRepoTree(c *Ctx, args []string) int { |
| 242 | const usage = "repo tree <owner/name> [<path>] [--ref <ref>]" | |
| 243 | pos, ref, code := readArgs(c, args, usage, 2) | |
| 241 | pos, ref, code := readArgs(c, args, c.Cmd.Usage, 2) | |
| 244 | 242 | if code >= 0 { |
| 245 | 243 | return code |
| 246 | 244 | } |
| 247 | 245 | if len(pos) == 0 { |
| 248 | return c.fail(protocol.ExitUsage, "usage: %s", usage) | |
| 246 | return c.usage() | |
| 249 | 247 | } |
| 250 | 248 | repo, code := resolveRepo(c, pos[0], policy.CanRead) |
| 251 | 249 | if code >= 0 { |
| @@ -303,13 +301,12 @@ func sizeCol(e entryOut) string { | ||
| 303 | 301 | } |
| 304 | 302 | |
| 305 | 303 | func runRepoCat(c *Ctx, args []string) int { |
| 306 | const usage = "repo cat <owner/name> <path> [--ref <ref>]" | |
| 307 | pos, ref, code := readArgs(c, args, usage, 2) | |
| 304 | pos, ref, code := readArgs(c, args, c.Cmd.Usage, 2) | |
| 308 | 305 | if code >= 0 { |
| 309 | 306 | return code |
| 310 | 307 | } |
| 311 | 308 | if len(pos) != 2 { |
| 312 | return c.fail(protocol.ExitUsage, "usage: %s", usage) | |
| 309 | return c.usage() | |
| 313 | 310 | } |
| 314 | 311 | repo, code := resolveRepo(c, pos[0], policy.CanRead) |
| 315 | 312 | if code >= 0 { |
internal/control/register.go +5 −5
| @@ -45,7 +45,7 @@ func init() { | ||
| 45 | 45 | |
| 46 | 46 | func runEmailList(c *Ctx, args []string) int { |
| 47 | 47 | if len(args) != 0 { |
| 48 | return c.fail(protocol.ExitUsage, "usage: email list [--json]") | |
| 48 | return c.usage() | |
| 49 | 49 | } |
| 50 | 50 | emails, err := c.Store.ListEmails(c.User.ID) |
| 51 | 51 | if err != nil { |
| @@ -89,7 +89,7 @@ func emailErr(c *Ctx, verb string, err error) int { | ||
| 89 | 89 | |
| 90 | 90 | func runEmailRemove(c *Ctx, args []string) int { |
| 91 | 91 | if len(args) != 1 { |
| 92 | return c.fail(protocol.ExitUsage, "usage: email remove <address>") | |
| 92 | return c.usage() | |
| 93 | 93 | } |
| 94 | 94 | if err := c.Store.RemoveEmail(c.User.ID, args[0]); err != nil { |
| 95 | 95 | return emailErr(c, "removing address", err) |
| @@ -101,7 +101,7 @@ func runEmailRemove(c *Ctx, args []string) int { | ||
| 101 | 101 | |
| 102 | 102 | func runEmailPrimary(c *Ctx, args []string) int { |
| 103 | 103 | if len(args) != 1 { |
| 104 | return c.fail(protocol.ExitUsage, "usage: email primary <address>") | |
| 104 | return c.usage() | |
| 105 | 105 | } |
| 106 | 106 | if err := c.Store.SetPrimaryEmail(c.User.ID, args[0]); err != nil { |
| 107 | 107 | return emailErr(c, "setting primary", err) |
| @@ -136,7 +136,7 @@ const maxEmailAddsPerHour = 5 | ||
| 136 | 136 | |
| 137 | 137 | func runEmailAdd(c *Ctx, args []string) int { |
| 138 | 138 | if len(args) != 1 || !strings.Contains(args[0], "@") { |
| 139 | return c.fail(protocol.ExitUsage, "usage: email add <address>") | |
| 139 | return c.usage() | |
| 140 | 140 | } |
| 141 | 141 | if c.Cfg.Mail.SMTPHost == "" { |
| 142 | 142 | return c.fail(protocol.ExitFailure, "this instance has no SMTP configured; ask an admin to verify the address (gitbayd admin email verify)") |
| @@ -161,7 +161,7 @@ func runEmailAdd(c *Ctx, args []string) int { | ||
| 161 | 161 | |
| 162 | 162 | func runEmailVerify(c *Ctx, args []string) int { |
| 163 | 163 | if len(args) != 1 { |
| 164 | return c.fail(protocol.ExitUsage, "usage: email verify <code>") | |
| 164 | return c.usage() | |
| 165 | 165 | } |
| 166 | 166 | hash := store.HashToken(args[0]) |
| 167 | 167 | address, err := c.Store.ConsumeEmailToken(c.User.ID, hash) |
internal/control/release.go +8 −10
| @@ -76,15 +76,14 @@ func releaseRef(c *Ctx, args []string, perm func(store.User, store.Repo, string) | ||
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | func runReleaseCreate(c *Ctx, args []string) int { |
| 79 | const usage = "usage: release create <owner/name> <tag> [--title <t>] [--notes <n> | --file -] [--format md|org]" | |
| 80 | f, err := parseFlags(args, flagSpec{Values: []string{"--title", "--notes", "--file", "--format"}, MaxPos: 2, Usage: usage}) | |
| 79 | f, err := parseFlags(args, flagSpec{Values: []string{"--title", "--notes", "--file", "--format"}, MaxPos: 2, Usage: c.Cmd.Usage}) | |
| 81 | 80 | if err != nil { |
| 82 | 81 | return c.fail(protocol.ExitUsage, "%v", err) |
| 83 | 82 | } |
| 84 | 83 | path, tag := f.pos(0), f.pos(1) |
| 85 | 84 | title, notes, file, format := f.Value("--title"), f.Value("--notes"), f.Value("--file"), f.Value("--format") |
| 86 | 85 | if path == "" || tag == "" { |
| 87 | return c.fail(protocol.ExitUsage, usage) | |
| 86 | return c.usage() | |
| 88 | 87 | } |
| 89 | 88 | fmtName, err := markupFormat(format) |
| 90 | 89 | if err != nil { |
| @@ -149,8 +148,7 @@ func releaseToOut(r store.Release, withNotes bool) releaseOut { | ||
| 149 | 148 | } |
| 150 | 149 | |
| 151 | 150 | func runReleaseEdit(c *Ctx, args []string) int { |
| 152 | const usage = "usage: release edit <owner/name> <tag> [--title <t>] [--notes <n> | --file -] [--format md|org]" | |
| 153 | f, err := parseFlags(args, flagSpec{Values: []string{"--title", "--notes", "--file", "--format"}, MaxPos: 2, Usage: usage}) | |
| 151 | f, err := parseFlags(args, flagSpec{Values: []string{"--title", "--notes", "--file", "--format"}, MaxPos: 2, Usage: c.Cmd.Usage}) | |
| 154 | 152 | if err != nil { |
| 155 | 153 | return c.fail(protocol.ExitUsage, "%v", err) |
| 156 | 154 | } |
| @@ -162,7 +160,7 @@ func runReleaseEdit(c *Ctx, args []string) int { | ||
| 162 | 160 | return c.failInput(err) |
| 163 | 161 | } |
| 164 | 162 | if path == "" || tag == "" || (!setTitle && !setNotes && fmtName == "") { |
| 165 | return c.fail(protocol.ExitUsage, usage) | |
| 163 | return c.usage() | |
| 166 | 164 | } |
| 167 | 165 | repo, code := resolveRepo(c, path, policy.CanWrite) |
| 168 | 166 | if code >= 0 { |
| @@ -200,7 +198,7 @@ func runReleaseEdit(c *Ctx, args []string) int { | ||
| 200 | 198 | |
| 201 | 199 | func runReleaseList(c *Ctx, args []string) int { |
| 202 | 200 | if len(args) != 1 { |
| 203 | return c.fail(protocol.ExitUsage, "usage: release list <owner/name>") | |
| 201 | return c.usage() | |
| 204 | 202 | } |
| 205 | 203 | repo, code := resolveRepo(c, args[0], policy.CanRead) |
| 206 | 204 | if code >= 0 { |
| @@ -267,7 +265,7 @@ func runReleaseDelete(c *Ctx, args []string) int { | ||
| 267 | 265 | |
| 268 | 266 | func runAssetAdd(c *Ctx, args []string) int { |
| 269 | 267 | if len(args) != 3 { |
| 270 | return c.fail(protocol.ExitUsage, "usage: release asset add <owner/name> <tag> <filename> < file") | |
| 268 | return c.usage() | |
| 271 | 269 | } |
| 272 | 270 | repo, rel, code := releaseRef(c, args[:2], policy.CanWrite) |
| 273 | 271 | if code >= 0 { |
| @@ -319,7 +317,7 @@ func runAssetAdd(c *Ctx, args []string) int { | ||
| 319 | 317 | |
| 320 | 318 | func runAssetGet(c *Ctx, args []string) int { |
| 321 | 319 | if len(args) != 3 { |
| 322 | return c.fail(protocol.ExitUsage, "usage: release asset get <owner/name> <tag> <filename> > file") | |
| 320 | return c.usage() | |
| 323 | 321 | } |
| 324 | 322 | repo, rel, code := releaseRef(c, args[:2], policy.CanRead) |
| 325 | 323 | if code >= 0 { |
| @@ -342,7 +340,7 @@ func runAssetGet(c *Ctx, args []string) int { | ||
| 342 | 340 | |
| 343 | 341 | func runAssetRemove(c *Ctx, args []string) int { |
| 344 | 342 | if len(args) != 3 { |
| 345 | return c.fail(protocol.ExitUsage, "usage: release asset remove <owner/name> <tag> <filename>") | |
| 343 | return c.usage() | |
| 346 | 344 | } |
| 347 | 345 | repo, rel, code := releaseRef(c, args[:2], policy.CanWrite) |
| 348 | 346 | if code >= 0 { |
internal/control/repo.go +27 −35
| @@ -181,7 +181,7 @@ func runRepoCreate(c *Ctx, args []string) int { | ||
| 181 | 181 | } |
| 182 | 182 | owner, name, ok := strings.Cut(path, "/") |
| 183 | 183 | if !ok { |
| 184 | return c.fail(protocol.ExitUsage, "usage: repo create <owner/name> [--private]") | |
| 184 | return c.usage() | |
| 185 | 185 | } |
| 186 | 186 | if err := policyValidateRepoName(name); err != nil { |
| 187 | 187 | return c.failInput(err) |
| @@ -247,7 +247,7 @@ func runRepoList(c *Ctx, args []string) int { | ||
| 247 | 247 | return code |
| 248 | 248 | } |
| 249 | 249 | if len(args) != 0 { |
| 250 | return c.fail(protocol.ExitUsage, "usage: repo list [--limit <n>] [--cursor <c>]") | |
| 250 | return c.usage() | |
| 251 | 251 | } |
| 252 | 252 | repos, err := c.Store.ListReposForUser(c.User.ID, p.queryLimit(), p.key) |
| 253 | 253 | if err != nil { |
| @@ -278,7 +278,7 @@ func runRepoList(c *Ctx, args []string) int { | ||
| 278 | 278 | |
| 279 | 279 | func runRepoShow(c *Ctx, args []string) int { |
| 280 | 280 | if len(args) != 1 { |
| 281 | return c.fail(protocol.ExitUsage, "usage: repo show <owner/name>") | |
| 281 | return c.usage() | |
| 282 | 282 | } |
| 283 | 283 | repo, code := resolveRepo(c, args[0], policy.CanRead) |
| 284 | 284 | if code >= 0 { |
| @@ -393,7 +393,7 @@ func runRepoShow(c *Ctx, args []string) int { | ||
| 393 | 393 | |
| 394 | 394 | func runRepoTransfer(c *Ctx, args []string) int { |
| 395 | 395 | if len(args) != 2 { |
| 396 | return c.fail(protocol.ExitUsage, "usage: repo transfer <owner/name> <new-owner>") | |
| 396 | return c.usage() | |
| 397 | 397 | } |
| 398 | 398 | repo, code := resolveRepo(c, args[0], policy.CanAdmin) |
| 399 | 399 | if code >= 0 { |
| @@ -452,7 +452,7 @@ func runRepoTransfer(c *Ctx, args []string) int { | ||
| 452 | 452 | |
| 453 | 453 | func runRepoRename(c *Ctx, args []string) int { |
| 454 | 454 | if len(args) != 2 { |
| 455 | return c.fail(protocol.ExitUsage, "usage: repo rename <owner/name> <new-name>") | |
| 455 | return c.usage() | |
| 456 | 456 | } |
| 457 | 457 | repo, code := resolveRepo(c, args[0], policy.CanAdmin) |
| 458 | 458 | if code >= 0 { |
| @@ -496,11 +496,11 @@ func runRepoDelete(c *Ctx, args []string) int { | ||
| 496 | 496 | } else if path == "" { |
| 497 | 497 | path = a |
| 498 | 498 | } else { |
| 499 | return c.fail(protocol.ExitUsage, "usage: repo delete <owner/name> --yes") | |
| 499 | return c.usage() | |
| 500 | 500 | } |
| 501 | 501 | } |
| 502 | 502 | if path == "" { |
| 503 | return c.fail(protocol.ExitUsage, "usage: repo delete <owner/name> --yes") | |
| 503 | return c.usage() | |
| 504 | 504 | } |
| 505 | 505 | repo, code := resolveRepo(c, path, policy.CanAdmin) |
| 506 | 506 | if code >= 0 { |
| @@ -540,7 +540,7 @@ func deleteRepo(c *Ctx, repo store.Repo) int { | ||
| 540 | 540 | |
| 541 | 541 | func runAccessGrant(c *Ctx, args []string) int { |
| 542 | 542 | if len(args) != 3 || !slices.Contains([]string{"read", "write", "admin"}, args[2]) { |
| 543 | return c.fail(protocol.ExitUsage, "usage: repo access grant <owner/name> <user> read|write|admin") | |
| 543 | return c.usage() | |
| 544 | 544 | } |
| 545 | 545 | repo, code := resolveRepo(c, args[0], policy.CanAdmin) |
| 546 | 546 | if code >= 0 { |
| @@ -559,7 +559,7 @@ func runAccessGrant(c *Ctx, args []string) int { | ||
| 559 | 559 | |
| 560 | 560 | func runAccessRevoke(c *Ctx, args []string) int { |
| 561 | 561 | if len(args) != 2 { |
| 562 | return c.fail(protocol.ExitUsage, "usage: repo access revoke <owner/name> <user>") | |
| 562 | return c.usage() | |
| 563 | 563 | } |
| 564 | 564 | repo, code := resolveRepo(c, args[0], policy.CanAdmin) |
| 565 | 565 | if code >= 0 { |
| @@ -581,7 +581,7 @@ func runAccessRevoke(c *Ctx, args []string) int { | ||
| 581 | 581 | |
| 582 | 582 | func runAccessList(c *Ctx, args []string) int { |
| 583 | 583 | if len(args) != 1 { |
| 584 | return c.fail(protocol.ExitUsage, "usage: repo access list <owner/name>") | |
| 584 | return c.usage() | |
| 585 | 585 | } |
| 586 | 586 | repo, code := resolveRepo(c, args[0], policy.CanAdmin) |
| 587 | 587 | if code >= 0 { |
| @@ -609,7 +609,7 @@ func runAccessList(c *Ctx, args []string) int { | ||
| 609 | 609 | |
| 610 | 610 | func runSettingsShow(c *Ctx, args []string) int { |
| 611 | 611 | if len(args) != 1 { |
| 612 | return c.fail(protocol.ExitUsage, "usage: repo settings show <owner/name>") | |
| 612 | return c.usage() | |
| 613 | 613 | } |
| 614 | 614 | repo, code := resolveRepo(c, args[0], policy.CanAdmin) |
| 615 | 615 | if code >= 0 { |
| @@ -623,7 +623,7 @@ func runSettingsShow(c *Ctx, args []string) int { | ||
| 623 | 623 | |
| 624 | 624 | func runSetDescription(c *Ctx, args []string) int { |
| 625 | 625 | if len(args) != 2 { |
| 626 | return c.fail(protocol.ExitUsage, "usage: repo settings description <owner/name> <text>") | |
| 626 | return c.usage() | |
| 627 | 627 | } |
| 628 | 628 | repo, code := resolveRepo(c, args[0], policy.CanAdmin) |
| 629 | 629 | if code >= 0 { |
| @@ -640,7 +640,7 @@ func runSetDescription(c *Ctx, args []string) int { | ||
| 640 | 640 | |
| 641 | 641 | func runSetDefaultBranch(c *Ctx, args []string) int { |
| 642 | 642 | if len(args) != 2 { |
| 643 | return c.fail(protocol.ExitUsage, "usage: repo settings default-branch <owner/name> <branch>") | |
| 643 | return c.usage() | |
| 644 | 644 | } |
| 645 | 645 | repo, code := resolveRepo(c, args[0], policy.CanAdmin) |
| 646 | 646 | if code >= 0 { |
| @@ -664,7 +664,7 @@ func runSetDefaultBranch(c *Ctx, args []string) int { | ||
| 664 | 664 | |
| 665 | 665 | func runSetWebsite(c *Ctx, args []string) int { |
| 666 | 666 | if len(args) != 2 { |
| 667 | return c.fail(protocol.ExitUsage, "usage: repo settings website <owner/name> <url>") | |
| 667 | return c.usage() | |
| 668 | 668 | } |
| 669 | 669 | site := strings.TrimSpace(args[1]) |
| 670 | 670 | if err := validateWebsite(site); err != nil { |
| @@ -691,7 +691,7 @@ func runSetWebsite(c *Ctx, args []string) int { | ||
| 691 | 691 | |
| 692 | 692 | func runSetVisibility(c *Ctx, args []string) int { |
| 693 | 693 | if len(args) != 2 || (args[1] != "public" && args[1] != "private") { |
| 694 | return c.fail(protocol.ExitUsage, "usage: repo settings visibility <owner/name> public|private") | |
| 694 | return c.usage() | |
| 695 | 695 | } |
| 696 | 696 | repo, code := resolveRepo(c, args[0], policy.CanAdmin) |
| 697 | 697 | if code >= 0 { |
| @@ -724,7 +724,7 @@ func setRepoVisibility(c *Ctx, repo store.Repo, visibility string) int { | ||
| 724 | 724 | |
| 725 | 725 | func runGitDaemon(c *Ctx, args []string) int { |
| 726 | 726 | if len(args) != 2 || (args[1] != "on" && args[1] != "off") { |
| 727 | return c.fail(protocol.ExitUsage, "usage: repo settings git-daemon <owner/name> on|off") | |
| 727 | return c.usage() | |
| 728 | 728 | } |
| 729 | 729 | repo, code := resolveRepo(c, args[0], policy.CanAdmin) |
| 730 | 730 | if code >= 0 { |
| @@ -748,12 +748,8 @@ func runArchive(c *Ctx, args []string) int { return setArchived(c, args, true) | ||
| 748 | 748 | func runUnarchive(c *Ctx, args []string) int { return setArchived(c, args, false) } |
| 749 | 749 | |
| 750 | 750 | func setArchived(c *Ctx, args []string, archived bool) int { |
| 751 | verb := "archive" | |
| 752 | if !archived { | |
| 753 | verb = "unarchive" | |
| 754 | } | |
| 755 | 751 | if len(args) != 1 { |
| 756 | return c.fail(protocol.ExitUsage, "usage: repo %s <owner/name>", verb) | |
| 752 | return c.usage() | |
| 757 | 753 | } |
| 758 | 754 | repo, code := resolveRepo(c, args[0], policy.CanAdmin) |
| 759 | 755 | if code >= 0 { |
| @@ -782,7 +778,7 @@ func archiveRepo(c *Ctx, repo store.Repo, archived bool) int { | ||
| 782 | 778 | |
| 783 | 779 | func runTopicsList(c *Ctx, args []string) int { |
| 784 | 780 | if len(args) != 1 { |
| 785 | return c.fail(protocol.ExitUsage, "usage: repo topics <owner/name>") | |
| 781 | return c.usage() | |
| 786 | 782 | } |
| 787 | 783 | repo, code := resolveRepo(c, args[0], policy.CanRead) |
| 788 | 784 | if code >= 0 { |
| @@ -803,12 +799,8 @@ func runTopicsAdd(c *Ctx, args []string) int { return editTopics(c, args, tru | ||
| 803 | 799 | func runTopicsRemove(c *Ctx, args []string) int { return editTopics(c, args, false) } |
| 804 | 800 | |
| 805 | 801 | func editTopics(c *Ctx, args []string, add bool) int { |
| 806 | verb := "add" | |
| 807 | if !add { | |
| 808 | verb = "remove" | |
| 809 | } | |
| 810 | 802 | if len(args) < 2 { |
| 811 | return c.fail(protocol.ExitUsage, "usage: repo topics %s <owner/name> <topic>...", verb) | |
| 803 | return c.usage() | |
| 812 | 804 | } |
| 813 | 805 | repo, code := resolveRepo(c, args[0], policy.CanAdmin) |
| 814 | 806 | if code >= 0 { |
| @@ -862,7 +854,7 @@ func editTopics(c *Ctx, args []string, add bool) int { | ||
| 862 | 854 | // and topics of every repository the caller can see. |
| 863 | 855 | func runRepoSearch(c *Ctx, args []string) int { |
| 864 | 856 | if len(args) != 1 { |
| 865 | return c.fail(protocol.ExitUsage, "usage: repo search <query>") | |
| 857 | return c.usage() | |
| 866 | 858 | } |
| 867 | 859 | if err := validQuery(args[0]); err != nil { |
| 868 | 860 | return c.failInput(err) |
| @@ -929,7 +921,7 @@ func runRepoGrep(c *Ctx, args []string) int { | ||
| 929 | 921 | } |
| 930 | 922 | path, query, ref := f.pos(0), f.pos(1), f.Value("--ref") |
| 931 | 923 | if path == "" || query == "" { |
| 932 | return c.fail(protocol.ExitUsage, "usage: repo grep <owner/name> <query> [--ref <ref>]") | |
| 924 | return c.usage() | |
| 933 | 925 | } |
| 934 | 926 | if err := validQuery(query); err != nil { |
| 935 | 927 | return c.failInput(err) |
| @@ -974,7 +966,7 @@ func setPinned(c *Ctx, args []string, pin bool) int { | ||
| 974 | 966 | verb = "unpin" |
| 975 | 967 | } |
| 976 | 968 | if len(args) != 1 { |
| 977 | return c.fail(protocol.ExitUsage, "usage: repo %s <owner/name>", verb) | |
| 969 | return c.usage() | |
| 978 | 970 | } |
| 979 | 971 | repo, code := resolveRepo(c, args[0], policy.CanRead) |
| 980 | 972 | if code >= 0 { |
| @@ -1008,7 +1000,7 @@ func setBookmarked(c *Ctx, args []string, on bool) int { | ||
| 1008 | 1000 | verb = "unbookmark" |
| 1009 | 1001 | } |
| 1010 | 1002 | if len(args) != 1 { |
| 1011 | return c.fail(protocol.ExitUsage, "usage: repo %s <owner/name>", verb) | |
| 1003 | return c.usage() | |
| 1012 | 1004 | } |
| 1013 | 1005 | repo, code := resolveRepo(c, args[0], policy.CanRead) |
| 1014 | 1006 | if code >= 0 { |
| @@ -1040,7 +1032,7 @@ type BookmarkOut struct { | ||
| 1040 | 1032 | |
| 1041 | 1033 | func runRepoBookmarks(c *Ctx, args []string) int { |
| 1042 | 1034 | if len(args) != 0 { |
| 1043 | return c.fail(protocol.ExitUsage, "usage: repo bookmarks") | |
| 1035 | return c.usage() | |
| 1044 | 1036 | } |
| 1045 | 1037 | repos, err := c.Store.ListBookmarks(c.User.ID) |
| 1046 | 1038 | if err != nil { |
| @@ -1077,7 +1069,7 @@ func runUnprotectTag(c *Ctx, args []string) int { return setProtectTag(c, args, | ||
| 1077 | 1069 | |
| 1078 | 1070 | func setProtectTag(c *Ctx, args []string, protect bool) int { |
| 1079 | 1071 | if len(args) != 2 { |
| 1080 | return c.fail(protocol.ExitUsage, "usage: repo settings protect-tag|unprotect-tag <owner/name> <glob>") | |
| 1072 | return c.usage() | |
| 1081 | 1073 | } |
| 1082 | 1074 | glob := args[1] |
| 1083 | 1075 | if _, err := path.Match(glob, "x"); err != nil || glob == "" { |
| @@ -1114,7 +1106,7 @@ func runUnprotect(c *Ctx, args []string) int { return setProtect(c, args, false) | ||
| 1114 | 1106 | |
| 1115 | 1107 | func setProtect(c *Ctx, args []string, protect bool) int { |
| 1116 | 1108 | if len(args) != 2 { |
| 1117 | return c.fail(protocol.ExitUsage, "usage: repo settings protect|unprotect <owner/name> <branch>") | |
| 1109 | return c.usage() | |
| 1118 | 1110 | } |
| 1119 | 1111 | repo, code := resolveRepo(c, args[0], policy.CanAdmin) |
| 1120 | 1112 | if code >= 0 { |
| @@ -1149,7 +1141,7 @@ func setProtect(c *Ctx, args []string, protect bool) int { | ||
| 1149 | 1141 | func runRepoDiff(c *Ctx, args []string) int { |
| 1150 | 1142 | f, err := parseFlags(args, flagSpec{MaxPos: 3, Usage: "repo diff <owner/name> <base> <head>"}) |
| 1151 | 1143 | if err != nil || len(f.Pos) != 3 { |
| 1152 | return c.fail(protocol.ExitUsage, "usage: repo diff <owner/name> <base> <head>") | |
| 1144 | return c.usage() | |
| 1153 | 1145 | } |
| 1154 | 1146 | repo, code := resolveRepo(c, f.pos(0), policy.CanRead) |
| 1155 | 1147 | if code >= 0 { |
internal/control/runnerrepo.go +3 −3
| @@ -33,7 +33,7 @@ func init() { | ||
| 33 | 33 | func runRepoRunnerAdd(c *Ctx, args []string) int { |
| 34 | 34 | f, err := parseFlags(args, flagSpec{MaxPos: 1, Usage: "repo runner add <owner/name> < key.pub"}) |
| 35 | 35 | if err != nil || len(f.Pos) != 1 { |
| 36 | return c.fail(protocol.ExitUsage, "usage: repo runner add <owner/name> < key.pub") | |
| 36 | return c.usage() | |
| 37 | 37 | } |
| 38 | 38 | repo, code := resolveRepo(c, f.Pos[0], policy.CanAdmin) |
| 39 | 39 | if code >= 0 { |
| @@ -95,7 +95,7 @@ func runRepoRunnerAdd(c *Ctx, args []string) int { | ||
| 95 | 95 | |
| 96 | 96 | func runRepoRunnerList(c *Ctx, args []string) int { |
| 97 | 97 | if len(args) != 1 { |
| 98 | return c.fail(protocol.ExitUsage, "usage: repo runner list <owner/name>") | |
| 98 | return c.usage() | |
| 99 | 99 | } |
| 100 | 100 | repo, code := resolveRepo(c, args[0], policy.CanAdmin) |
| 101 | 101 | if code >= 0 { |
| @@ -125,7 +125,7 @@ func runRepoRunnerList(c *Ctx, args []string) int { | ||
| 125 | 125 | |
| 126 | 126 | func runRepoRunnerRemove(c *Ctx, args []string) int { |
| 127 | 127 | if len(args) != 2 { |
| 128 | return c.fail(protocol.ExitUsage, "usage: repo runner remove <owner/name> <fingerprint>") | |
| 128 | return c.usage() | |
| 129 | 129 | } |
| 130 | 130 | repo, code := resolveRepo(c, args[0], policy.CanAdmin) |
| 131 | 131 | if code >= 0 { |
internal/control/search.go +2 −3
| @@ -77,13 +77,12 @@ func Search(st *store.Store, root string, userID int64, q string, kinds []string | ||
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | func runSearch(c *Ctx, args []string) int { |
| 80 | const usage = "search <query> [--kind repo|issue|mr]" | |
| 81 | f, err := parseFlags(args, flagSpec{Multi: []string{"--kind"}, MaxPos: 1, Usage: usage}) | |
| 80 | f, err := parseFlags(args, flagSpec{Multi: []string{"--kind"}, MaxPos: 1, Usage: c.Cmd.Usage}) | |
| 82 | 81 | if err != nil { |
| 83 | 82 | return c.fail(protocol.ExitUsage, "%v", err) |
| 84 | 83 | } |
| 85 | 84 | if len(f.Pos) != 1 { |
| 86 | return c.fail(protocol.ExitUsage, "usage: %s", usage) | |
| 85 | return c.usage() | |
| 87 | 86 | } |
| 88 | 87 | if err := validQuery(f.Pos[0]); err != nil { |
| 89 | 88 | return c.failInput(err) |
internal/control/sig.go +4 −5
| @@ -37,7 +37,7 @@ func init() { | ||
| 37 | 37 | |
| 38 | 38 | func runPGPAdd(c *Ctx, args []string) int { |
| 39 | 39 | if len(args) != 0 { |
| 40 | return c.fail(protocol.ExitUsage, "usage: pgp add < key.asc") | |
| 40 | return c.usage() | |
| 41 | 41 | } |
| 42 | 42 | raw, err := io.ReadAll(io.LimitReader(c.Stdin, 1<<20)) |
| 43 | 43 | if err != nil { |
| @@ -88,7 +88,7 @@ func runPGPList(c *Ctx, args []string) int { | ||
| 88 | 88 | |
| 89 | 89 | func runPGPRemove(c *Ctx, args []string) int { |
| 90 | 90 | if len(args) != 1 { |
| 91 | return c.fail(protocol.ExitUsage, "usage: pgp remove <fingerprint>") | |
| 91 | return c.usage() | |
| 92 | 92 | } |
| 93 | 93 | if err := c.Store.RemovePGPKey(c.User.ID, args[0]); err != nil { |
| 94 | 94 | if errors.Is(err, store.ErrNotFound) { |
| @@ -140,7 +140,7 @@ func runRepoLog(c *Ctx, args []string) int { | ||
| 140 | 140 | limit = n |
| 141 | 141 | } |
| 142 | 142 | if path == "" { |
| 143 | return c.fail(protocol.ExitUsage, "usage: repo log <owner/name> [--ref <r>] [--limit n] [--path <file>]") | |
| 143 | return c.usage() | |
| 144 | 144 | } |
| 145 | 145 | repo, code := resolveRepo(c, path, policy.CanRead) |
| 146 | 146 | if code >= 0 { |
| @@ -221,9 +221,8 @@ func runRepoLog(c *Ctx, args []string) int { | ||
| 221 | 221 | // statuses, and its patch. The web's commit page read these straight from |
| 222 | 222 | // git, which is why no other surface could open a commit. |
| 223 | 223 | func runRepoCommit(c *Ctx, args []string) int { |
| 224 | const usage = "repo commit <owner/name> <sha>" | |
| 225 | 224 | if len(args) != 2 { |
| 226 | return c.fail(protocol.ExitUsage, "usage: %s", usage) | |
| 225 | return c.usage() | |
| 227 | 226 | } |
| 228 | 227 | repo, code := resolveRepo(c, args[0], policy.CanRead) |
| 229 | 228 | if code >= 0 { |
internal/control/snippet.go +10 −12
| @@ -132,14 +132,13 @@ func newSnippetID() string { | ||
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | func runSnippetCreate(c *Ctx, args []string) int { |
| 135 | const usage = "usage: snippet create <filename> [--description <d>] [--visibility public|unlisted|private] < file" | |
| 136 | f, err := parseFlags(args, flagSpec{Values: []string{"--description", "--visibility"}, MaxPos: 1, Usage: usage}) | |
| 135 | f, err := parseFlags(args, flagSpec{Values: []string{"--description", "--visibility"}, MaxPos: 1, Usage: c.Cmd.Usage}) | |
| 137 | 136 | if err != nil { |
| 138 | 137 | return c.fail(protocol.ExitUsage, "%v", err) |
| 139 | 138 | } |
| 140 | 139 | name := f.pos(0) |
| 141 | 140 | if name == "" { |
| 142 | return c.fail(protocol.ExitUsage, usage) | |
| 141 | return c.usage() | |
| 143 | 142 | } |
| 144 | 143 | if code := checkSnippetFileName(c, name); code >= 0 { |
| 145 | 144 | return code |
| @@ -186,7 +185,7 @@ func runSnippetCreate(c *Ctx, args []string) int { | ||
| 186 | 185 | |
| 187 | 186 | func runSnippetShow(c *Ctx, args []string) int { |
| 188 | 187 | if len(args) != 1 { |
| 189 | return c.fail(protocol.ExitUsage, "usage: snippet show <id>") | |
| 188 | return c.usage() | |
| 190 | 189 | } |
| 191 | 190 | sn, code := snippetRef(c, args[0], false) |
| 192 | 191 | if code >= 0 { |
| @@ -215,7 +214,7 @@ func runSnippetList(c *Ctx, args []string) int { | ||
| 215 | 214 | return code |
| 216 | 215 | } |
| 217 | 216 | if len(rest) > 1 { |
| 218 | return c.fail(protocol.ExitUsage, "usage: snippet list [<owner>] [--limit n] [--cursor c]") | |
| 217 | return c.usage() | |
| 219 | 218 | } |
| 220 | 219 | owner := c.User |
| 221 | 220 | if len(rest) == 1 { |
| @@ -253,13 +252,12 @@ func runSnippetList(c *Ctx, args []string) int { | ||
| 253 | 252 | } |
| 254 | 253 | |
| 255 | 254 | func runSnippetEdit(c *Ctx, args []string) int { |
| 256 | const usage = "usage: snippet edit <id> [--description <d>] [--visibility public|unlisted|private]" | |
| 257 | f, err := parseFlags(args, flagSpec{Values: []string{"--description", "--visibility"}, MaxPos: 1, Usage: usage}) | |
| 255 | f, err := parseFlags(args, flagSpec{Values: []string{"--description", "--visibility"}, MaxPos: 1, Usage: c.Cmd.Usage}) | |
| 258 | 256 | if err != nil { |
| 259 | 257 | return c.fail(protocol.ExitUsage, "%v", err) |
| 260 | 258 | } |
| 261 | 259 | if f.pos(0) == "" || (!f.Has("--description") && !f.Has("--visibility")) { |
| 262 | return c.fail(protocol.ExitUsage, usage) | |
| 260 | return c.usage() | |
| 263 | 261 | } |
| 264 | 262 | sn, code := snippetRef(c, f.pos(0), true) |
| 265 | 263 | if code >= 0 { |
| @@ -289,7 +287,7 @@ func runSnippetEdit(c *Ctx, args []string) int { | ||
| 289 | 287 | |
| 290 | 288 | func runSnippetDelete(c *Ctx, args []string) int { |
| 291 | 289 | if len(args) != 1 { |
| 292 | return c.fail(protocol.ExitUsage, "usage: snippet delete <id>") | |
| 290 | return c.usage() | |
| 293 | 291 | } |
| 294 | 292 | sn, code := snippetRef(c, args[0], true) |
| 295 | 293 | if code >= 0 { |
| @@ -305,7 +303,7 @@ func runSnippetDelete(c *Ctx, args []string) int { | ||
| 305 | 303 | |
| 306 | 304 | func runSnippetFileSet(c *Ctx, args []string) int { |
| 307 | 305 | if len(args) != 2 { |
| 308 | return c.fail(protocol.ExitUsage, "usage: snippet file set <id> <filename> < file") | |
| 306 | return c.usage() | |
| 309 | 307 | } |
| 310 | 308 | sn, code := snippetRef(c, args[0], true) |
| 311 | 309 | if code >= 0 { |
| @@ -336,7 +334,7 @@ func runSnippetFileSet(c *Ctx, args []string) int { | ||
| 336 | 334 | |
| 337 | 335 | func runSnippetFileGet(c *Ctx, args []string) int { |
| 338 | 336 | if len(args) != 2 { |
| 339 | return c.fail(protocol.ExitUsage, "usage: snippet file get <id> <filename> > file") | |
| 337 | return c.usage() | |
| 340 | 338 | } |
| 341 | 339 | sn, code := snippetRef(c, args[0], false) |
| 342 | 340 | if code >= 0 { |
| @@ -360,7 +358,7 @@ func runSnippetFileGet(c *Ctx, args []string) int { | ||
| 360 | 358 | |
| 361 | 359 | func runSnippetFileRemove(c *Ctx, args []string) int { |
| 362 | 360 | if len(args) != 2 { |
| 363 | return c.fail(protocol.ExitUsage, "usage: snippet file remove <id> <filename>") | |
| 361 | return c.usage() | |
| 364 | 362 | } |
| 365 | 363 | sn, code := snippetRef(c, args[0], true) |
| 366 | 364 | if code >= 0 { |
internal/control/status.go +2 −2
| @@ -55,7 +55,7 @@ func runStatusSet(c *Ctx, args []string) int { | ||
| 55 | 55 | } |
| 56 | 56 | } |
| 57 | 57 | if path == "" || sha == "" || context == "" || !validStatusState[state] { |
| 58 | return c.fail(protocol.ExitUsage, "usage: status set <owner/name> <sha> --context <c> --state pending|success|failure|error") | |
| 58 | return c.usage() | |
| 59 | 59 | } |
| 60 | 60 | if url != "" && !strings.HasPrefix(url, "https://") && !strings.HasPrefix(url, "http://") { |
| 61 | 61 | return c.fail(protocol.ExitUsage, "--url must be http(s)") |
| @@ -86,7 +86,7 @@ func runStatusSet(c *Ctx, args []string) int { | ||
| 86 | 86 | |
| 87 | 87 | func runStatusList(c *Ctx, args []string) int { |
| 88 | 88 | if len(args) != 2 { |
| 89 | return c.fail(protocol.ExitUsage, "usage: status list <owner/name> <sha>") | |
| 89 | return c.usage() | |
| 90 | 90 | } |
| 91 | 91 | repo, code := resolveRepo(c, args[0], policy.CanRead) |
| 92 | 92 | if code >= 0 { |
internal/control/teams.go +8 −8
| @@ -89,7 +89,7 @@ func teamRef(c *Ctx, org store.Org, name string) (store.Team, int) { | ||
| 89 | 89 | |
| 90 | 90 | func runTeamCreate(c *Ctx, args []string) int { |
| 91 | 91 | if len(args) != 2 { |
| 92 | return c.fail(protocol.ExitUsage, "usage: org team create <org> <team>") | |
| 92 | return c.usage() | |
| 93 | 93 | } |
| 94 | 94 | org, code := orgAdminRef(c, args[0]) |
| 95 | 95 | if code >= 0 { |
| @@ -108,7 +108,7 @@ func runTeamCreate(c *Ctx, args []string) int { | ||
| 108 | 108 | |
| 109 | 109 | func runTeamDelete(c *Ctx, args []string) int { |
| 110 | 110 | if len(args) != 2 { |
| 111 | return c.fail(protocol.ExitUsage, "usage: org team delete <org> <team>") | |
| 111 | return c.usage() | |
| 112 | 112 | } |
| 113 | 113 | org, code := orgAdminRef(c, args[0]) |
| 114 | 114 | if code >= 0 { |
| @@ -128,7 +128,7 @@ func runTeamDelete(c *Ctx, args []string) int { | ||
| 128 | 128 | |
| 129 | 129 | func runTeamList(c *Ctx, args []string) int { |
| 130 | 130 | if len(args) != 1 { |
| 131 | return c.fail(protocol.ExitUsage, "usage: org team list <org>") | |
| 131 | return c.usage() | |
| 132 | 132 | } |
| 133 | 133 | org, code := orgMemberRef(c, args[0]) |
| 134 | 134 | if code >= 0 { |
| @@ -151,7 +151,7 @@ func runTeamList(c *Ctx, args []string) int { | ||
| 151 | 151 | |
| 152 | 152 | func runTeamShow(c *Ctx, args []string) int { |
| 153 | 153 | if len(args) != 2 { |
| 154 | return c.fail(protocol.ExitUsage, "usage: org team show <org> <team>") | |
| 154 | return c.usage() | |
| 155 | 155 | } |
| 156 | 156 | org, code := orgMemberRef(c, args[0]) |
| 157 | 157 | if code >= 0 { |
| @@ -191,7 +191,7 @@ func editTeamMembers(c *Ctx, args []string, add bool) int { | ||
| 191 | 191 | verb = "remove" |
| 192 | 192 | } |
| 193 | 193 | if len(args) < 3 { |
| 194 | return c.fail(protocol.ExitUsage, "usage: org team %s <org> <team> <user>...", verb) | |
| 194 | return c.usage() | |
| 195 | 195 | } |
| 196 | 196 | org, code := orgAdminRef(c, args[0]) |
| 197 | 197 | if code >= 0 { |
| @@ -233,7 +233,7 @@ func editTeamMembers(c *Ctx, args []string, add bool) int { | ||
| 233 | 233 | |
| 234 | 234 | func runTeamGrant(c *Ctx, args []string) int { |
| 235 | 235 | if len(args) != 4 || !slices.Contains([]string{"read", "write", "admin"}, args[3]) { |
| 236 | return c.fail(protocol.ExitUsage, "usage: org team grant <org> <team> <owner/name> read|write|admin") | |
| 236 | return c.usage() | |
| 237 | 237 | } |
| 238 | 238 | org, code := orgAdminRef(c, args[0]) |
| 239 | 239 | if code >= 0 { |
| @@ -257,7 +257,7 @@ func runTeamGrant(c *Ctx, args []string) int { | ||
| 257 | 257 | |
| 258 | 258 | func runTeamRevoke(c *Ctx, args []string) int { |
| 259 | 259 | if len(args) != 3 { |
| 260 | return c.fail(protocol.ExitUsage, "usage: org team revoke <org> <team> <owner/name>") | |
| 260 | return c.usage() | |
| 261 | 261 | } |
| 262 | 262 | org, code := orgAdminRef(c, args[0]) |
| 263 | 263 | if code >= 0 { |
| @@ -284,7 +284,7 @@ func runTeamRevoke(c *Ctx, args []string) int { | ||
| 284 | 284 | |
| 285 | 285 | func runOrgMembersRole(c *Ctx, args []string) int { |
| 286 | 286 | if len(args) != 2 || !slices.Contains([]string{"write", "read", "none"}, args[1]) { |
| 287 | return c.fail(protocol.ExitUsage, "usage: org settings members-role <org> write|read|none") | |
| 287 | return c.usage() | |
| 288 | 288 | } |
| 289 | 289 | org, code := orgAdminRef(c, args[0]) |
| 290 | 290 | if code >= 0 { |
internal/control/token.go +2 −2
| @@ -48,7 +48,7 @@ func runTokenCreate(c *Ctx, args []string) int { | ||
| 48 | 48 | scope = f.Value("--scope") |
| 49 | 49 | } |
| 50 | 50 | if name == "" || (scope != "full" && scope != "read") { |
| 51 | return c.fail(protocol.ExitUsage, "usage: token create --name <n> [--scope full|read] [--ttl 30d]") | |
| 51 | return c.usage() | |
| 52 | 52 | } |
| 53 | 53 | var expires *time.Time |
| 54 | 54 | if ttl != "" { |
| @@ -108,7 +108,7 @@ func runTokenList(c *Ctx, args []string) int { | ||
| 108 | 108 | |
| 109 | 109 | func runTokenRevoke(c *Ctx, args []string) int { |
| 110 | 110 | if len(args) != 1 { |
| 111 | return c.fail(protocol.ExitUsage, "usage: token revoke <name>") | |
| 111 | return c.usage() | |
| 112 | 112 | } |
| 113 | 113 | if err := c.Store.RevokeAPIToken(c.User.ID, args[0]); err != nil { |
| 114 | 114 | if errors.Is(err, store.ErrNotFound) { |
internal/control/web.go +3 −3
| @@ -26,7 +26,7 @@ func init() { | ||
| 26 | 26 | |
| 27 | 27 | func runWebSessionsList(c *Ctx, args []string) int { |
| 28 | 28 | if len(args) != 0 { |
| 29 | return c.fail(protocol.ExitUsage, "usage: web sessions list") | |
| 29 | return c.usage() | |
| 30 | 30 | } |
| 31 | 31 | sessions, err := c.Store.ListWebSessions(c.User.ID) |
| 32 | 32 | if err != nil { |
| @@ -41,7 +41,7 @@ func runWebSessionsList(c *Ctx, args []string) int { | ||
| 41 | 41 | |
| 42 | 42 | func runWebSessionsRevoke(c *Ctx, args []string) int { |
| 43 | 43 | if len(args) != 1 { |
| 44 | return c.fail(protocol.ExitUsage, "usage: web sessions revoke <id>|--all") | |
| 44 | return c.usage() | |
| 45 | 45 | } |
| 46 | 46 | if args[0] == "--all" { |
| 47 | 47 | n, err := c.Store.RevokeAllWebSessions(c.User.ID) |
| @@ -65,7 +65,7 @@ func runWebSessionsRevoke(c *Ctx, args []string) int { | ||
| 65 | 65 | |
| 66 | 66 | func runWebLogin(c *Ctx, args []string) int { |
| 67 | 67 | if len(args) != 0 { |
| 68 | return c.fail(protocol.ExitUsage, "usage: web login [--json]") | |
| 68 | return c.usage() | |
| 69 | 69 | } |
| 70 | 70 | if c.Cfg.Web.Mode != "accounts" { |
| 71 | 71 | return c.fail(protocol.ExitDenied, |
internal/control/webhook.go +5 −5
| @@ -40,7 +40,7 @@ func runWebhookAdd(c *Ctx, args []string) int { | ||
| 40 | 40 | events = f.Value("--events") |
| 41 | 41 | } |
| 42 | 42 | if path == "" || url == "" { |
| 43 | return c.fail(protocol.ExitUsage, "usage: webhook add <owner/name> <url> [--secret <s>] [--events <k1,k2>|*]") | |
| 43 | return c.usage() | |
| 44 | 44 | } |
| 45 | 45 | repo, code := resolveRepo(c, path, policy.CanAdmin) |
| 46 | 46 | if code >= 0 { |
| @@ -68,7 +68,7 @@ func runWebhookAdd(c *Ctx, args []string) int { | ||
| 68 | 68 | |
| 69 | 69 | func runWebhookList(c *Ctx, args []string) int { |
| 70 | 70 | if len(args) != 1 { |
| 71 | return c.fail(protocol.ExitUsage, "usage: webhook list <owner/name>") | |
| 71 | return c.usage() | |
| 72 | 72 | } |
| 73 | 73 | repo, code := resolveRepo(c, args[0], policy.CanAdmin) |
| 74 | 74 | if code >= 0 { |
| @@ -98,7 +98,7 @@ func runWebhookList(c *Ctx, args []string) int { | ||
| 98 | 98 | |
| 99 | 99 | func runWebhookRemove(c *Ctx, args []string) int { |
| 100 | 100 | if len(args) != 2 { |
| 101 | return c.fail(protocol.ExitUsage, "usage: webhook remove <owner/name> <id>") | |
| 101 | return c.usage() | |
| 102 | 102 | } |
| 103 | 103 | repo, code := resolveRepo(c, args[0], policy.CanAdmin) |
| 104 | 104 | if code >= 0 { |
| @@ -133,7 +133,7 @@ func runWebhookDeliveries(c *Ctx, args []string) int { | ||
| 133 | 133 | limit = n |
| 134 | 134 | } |
| 135 | 135 | if path == "" { |
| 136 | return c.fail(protocol.ExitUsage, "usage: webhook deliveries <owner/name> [--limit n]") | |
| 136 | return c.usage() | |
| 137 | 137 | } |
| 138 | 138 | repo, code := resolveRepo(c, path, policy.CanAdmin) |
| 139 | 139 | if code >= 0 { |
| @@ -169,7 +169,7 @@ func runWebhookDeliveries(c *Ctx, args []string) int { | ||
| 169 | 169 | |
| 170 | 170 | func runWebhookRedeliver(c *Ctx, args []string) int { |
| 171 | 171 | if len(args) != 2 { |
| 172 | return c.fail(protocol.ExitUsage, "usage: webhook redeliver <owner/name> <delivery-id>") | |
| 172 | return c.usage() | |
| 173 | 173 | } |
| 174 | 174 | repo, code := resolveRepo(c, args[0], policy.CanAdmin) |
| 175 | 175 | if code >= 0 { |
internal/control/wiki.go +2 −2
| @@ -79,7 +79,7 @@ func wikiPages(dir, branch string) []string { | ||
| 79 | 79 | |
| 80 | 80 | func runWikiList(c *Ctx, args []string) int { |
| 81 | 81 | if len(args) != 1 { |
| 82 | return c.fail(protocol.ExitUsage, "usage: wiki list <owner/name>") | |
| 82 | return c.usage() | |
| 83 | 83 | } |
| 84 | 84 | repo, dir, branch, code := wikiDir(c, args[0]) |
| 85 | 85 | if code >= 0 { |
| @@ -120,7 +120,7 @@ func wikiHome(pages []string) string { | ||
| 120 | 120 | |
| 121 | 121 | func runWikiShow(c *Ctx, args []string) int { |
| 122 | 122 | if len(args) < 1 || len(args) > 2 { |
| 123 | return c.fail(protocol.ExitUsage, "usage: wiki show <owner/name> [<page>]") | |
| 123 | return c.usage() | |
| 124 | 124 | } |
| 125 | 125 | repo, dir, branch, code := wikiDir(c, args[0]) |
| 126 | 126 | if code >= 0 { |