Sign in

Search issue titles and bodies, change requests and comments. Private repositories you cannot read are not included.

vole
Site
Clone

Read only, no credentials:

https://rodent.software/vole.git

Write over SSH with a registered key:

git clone ssh://git@rodent.software/vole.git

Self-hosted forge that lives in your Git repo.

Generate the CLI reference and help from one command table

f380ab70420ddf24f68931fa26e1288aff4acca6 · Keenan Nemetz · 23d ago · parent c284cb2c

Generate the CLI reference and help from one command table

The CLI documented itself four ways: a usage string per command group, inline
"usage: vole ..." strings in error paths, a per-group accepted-flag list, and
docs/cli.md, which was hand-written and had already drifted. `vole help` never
listed `run list`, `run show` or `run logs`, though all three exist and
`vole run -h` documented them; the reference listed them.

Each group now declares its subcommands, its flags (with argument and a one-line
description), its notes and its links in one table, in the file that parses it.
Three things render from that table:

  - `vole help` and `vole <group> -h`, which gain an Options section and now list
    every command and every flag;
  - `vole help --markdown`, which writes docs/cli.md;
  - `checkAllowed`, which refuses a flag the subcommand does not document — the
    per-group flag lists are gone, so the parser and the docs are one list.

verify regenerates docs/cli.md and fails on any difference, so the page cannot go
stale. cmd/vole/help_test.go checks that every flag has a description, that every
parsed flag is documented by some subcommand, that each subcommand accepts exactly
the flags it lists, and that the committed reference matches the binary.

Closes: 01M7359KQ6Z8W91N8WNWVV120B

cmd/vole/change.go +55−61

@@ -13,24 +13,51 @@ import (
13 13 "rodent.software/vole/metadata"
14 14 )
15 15
16 func changeUsage() string {
17 return `usage: vole change <command> [options] [args]
18
19 new --title <text> --base <branch> [--head <rev>] [--closes <issue>]... [-m <text> | -F <file>]
20 list [--state open|closed|all] [--format <fmt>]
21 show <id>
22 comment <id> [-m <text> | -F <file>] [--path <file> --line <n> [--side new|old]] [--reply-to <comment-id>]
23 edit-comment <id> <comment-id> [-m <text> | -F <file>]
24 rm-comment <id> <comment-id>
25 update <id> [--base <branch>] [--head <rev>] [--closes <issue>]... [--no-closes]
26 approve <id> [--as <account>]
27 merge <id>
28 close|reopen <id>
29
30 --no-push commits locally without pushing; -- ends option parsing. An id takes a
31 prefix or the #42 number: numbers are one sequence shared with issues, oldest
32 first. --closes takes an issue id or its number. A comment is yours to edit or
33 delete; an admin may repair somebody else's, audited.`
16 var changeGroup = &group{
17 Name: "change",
18 Summary: "open, review, approve, and land change requests",
19 Flags: []flagSpec{
20 {long: "title", short: "t", arg: "<title>", desc: "the request title"},
21 {long: "base", short: "b", arg: "<branch>", desc: "the branch the change lands on"},
22 {long: "head", short: "H", arg: "<rev>", desc: "the branch that follows the request, or a commit or tag to pin it to"},
23 {long: "closes", arg: "<issue>", desc: "an issue the request closes; repeatable, and comma lists are accepted"},
24 {long: "message", short: "m", arg: "<text>", desc: "the text; an alternative to -F"},
25 {long: "file", short: "F", arg: "<file|->", desc: "read the text from a file; - reads standard input"},
26 {long: "as", arg: "<account>", desc: "the account an approval is made for"},
27 {long: "path", arg: "<file>", desc: "the file a review comment is on"},
28 {long: "line", arg: "<n>", desc: "the line the comment is on; needs --path"},
29 {long: "side", arg: "<side>", desc: "new or old side of the diff (default new)"},
30 {long: "reply-to", arg: "<comment-id>", desc: "the comment this one replies to"},
31 {long: "state", arg: "<state>", desc: "open, closed, or all (default open)"},
32 {long: "remote", arg: "<name>", desc: "the remote naming the instance (default origin)"},
33 {long: "format", arg: "<fmt>", desc: "a template, or json"},
34 {long: "no-push", boolean: true, desc: "commit locally without pushing"},
35 {long: "no-closes", boolean: true, desc: "clear the issues the request closes"},
36 },
37 Subs: []subcommand{
38 {Name: "new", Synopsis: "change new --title <title> --base <branch> [--head <rev>] [--closes <issue>]... [-m <text> | -F <file>]", Flags: []string{"title", "base", "head", "closes", "message", "file", "remote", "no-push"}},
39 {Name: "list", Synopsis: "change list [--state <state>] [--format <fmt>]", Flags: []string{"state", "format", "remote"}, Notes: []string{"`--format json` prints one JSON object per request; any other value is used as a template."}},
40 {Name: "show", Synopsis: "change show <id>", Flags: []string{"remote"}, Notes: []string{"Prints the combined result and whether the landing is ready."}},
41 {Name: "comment", Synopsis: "change comment <id> [-m <text> | -F <file>] [--path <file> --line <n> [--side new|old]] [--reply-to <comment-id>]", Flags: []string{"message", "file", "path", "line", "side", "reply-to", "remote", "no-push"}},
42 {Name: "edit-comment", Synopsis: "change edit-comment <id> <comment-id> [-m <text> | -F <file>]", Flags: []string{"message", "file", "remote", "no-push"}},
43 {Name: "rm-comment", Synopsis: "change rm-comment <id> <comment-id>", Flags: []string{"remote", "no-push"}},
44 {Name: "update", Synopsis: "change update <id> [--base <branch>] [--head <rev>] [--closes <issue>]... [--no-closes]", Flags: []string{"base", "head", "closes", "no-closes", "remote", "no-push"}, Notes: []string{"`--base` retargets an open request, which is how a stacked request moves onto `main` after the branch below it lands; approvals named the old base and stop counting. `--closes` replaces the list, and `--no-closes` clears it."}},
45 {Name: "approve", Synopsis: "change approve <id> [--as <account>]", Flags: []string{"as", "remote", "no-push"}, Notes: []string{"An approval is only accepted from the account it names, and never by the author's own account."}},
46 {Name: "merge", Synopsis: "change merge <id>", Flags: []string{"remote"}, Notes: []string{"Lands the request. When the combined result is still building it says the request will merge when the result passes, which is the same merge-when-ready a click on the page arms."}},
47 {Name: "close", Synopsis: "change close <id>", Flags: []string{"remote", "no-push"}},
48 {Name: "reopen", Synopsis: "change reopen <id>", Flags: []string{"remote", "no-push"}},
49 },
50 Notes: []string{
51 "`change` also accepts `request`, `requests` and `cr` as compatibility aliases.\n" +
52 "An id takes a prefix or the #42 number: numbers are one sequence shared with\n" +
53 "issues, oldest first.",
54 "A request opened with `--head <branch>` follows that branch: a later push moves\n" +
55 "its head and invalidates the old approvals and checks. `--head <commit>` (or a\n" +
56 "tag) pins the request to that commit instead.",
57 "`--no-push` commits locally without pushing. A comment is yours to edit or\n" +
58 "delete; an admin may repair somebody else's, audited.",
59 },
60 See: []seeAlso{{"Change requests", "change-requests.md"}},
34 61 }
35 62
36 63 // cmdChange implements the change-request commands. A request is a promise to
@@ -39,62 +66,29 @@ delete; an admin may repair somebody else's, audited.`
39 66 // approval has to name the tip it actually reviewed.
40 67 func cmdChange(args []string) error {
41 68 if len(args) == 0 {
42 fmt.Fprint(os.Stderr, changeUsage()+"\n")
69 fmt.Fprint(os.Stderr, renderHelpText(changeGroup))
43 70 return usageErr{msg: "no change subcommand given"}
44 71 }
45 72 if args[0] == "-h" || args[0] == "--help" || args[0] == "help" {
46 fmt.Fprintln(os.Stdout, changeUsage())
73 fmt.Fprint(os.Stdout, renderHelpText(changeGroup))
47 74 return nil
48 75 }
49 76 sub := args[0]
50 specs := []flagSpec{
51 {long: "title", short: "t"},
52 {long: "base", short: "b"},
53 {long: "head", short: "H"},
54 {long: "closes"},
55 {long: "message", short: "m"},
56 {long: "file", short: "F"},
57 {long: "as"},
58 {long: "path"},
59 {long: "line"},
60 {long: "side"},
61 {long: "reply-to"},
62 {long: "state"},
63 {long: "remote"},
64 {long: "format"},
65 {long: "no-push", boolean: true},
66 {long: "no-closes", boolean: true},
67 }
68 f, err := parseFlags(args[1:], specs...)
77 f, err := parseFlags(args[1:], changeGroup.Flags...)
69 78 if err != nil {
70 79 return err
71 80 }
72 81 if f.help {
73 fmt.Fprintln(os.Stdout, changeUsage())
82 fmt.Fprint(os.Stdout, renderHelpText(changeGroup))
74 83 return nil
75 84 }
76 changeFlags := map[string][]string{
77 "new": {"title", "base", "head", "closes", "message", "file", "remote", "no-push"},
78 "comment": {"message", "file", "path", "line", "side", "reply-to", "remote", "no-push"},
79 "edit-comment": {"message", "file", "remote", "no-push"},
80 "rm-comment": {"remote", "no-push"},
81 "list": {"state", "format", "remote"},
82 "show": {"remote"},
83 "update": {"base", "head", "closes", "no-closes", "remote", "no-push"},
84 "approve": {"as", "remote", "no-push"},
85 "merge": {"remote"},
86 "close": {"remote", "no-push"},
87 "reopen": {"remote", "no-push"},
88 }
89 if names, ok := changeFlags[sub]; ok {
90 if err := f.checkAllowed("vole change "+sub, names...); err != nil {
91 return err
92 }
93 } else {
94 fmt.Fprint(os.Stderr, changeUsage()+"\n")
85 if !hasSubcommand("change", sub) {
86 fmt.Fprint(os.Stderr, renderHelpText(changeGroup))
95 87 return usagef("unknown change subcommand %q", sub)
96 88 }
97
89 if err := f.checkAllowed("vole change " + sub); err != nil {
90 return err
91 }
98 92 c, err := client.NewBranch(f.one("remote"), metadata.Ref)
99 93 if err != nil {
100 94 return err
@@ -525,7 +519,7 @@ func cmdChange(args []string) error {
525 519 fmt.Printf("%s\t%s\t%s\n", out.ID, out.State, out.Title)
526 520 return c.CommitAndPush(noPush, reapply)
527 521 }
528 fmt.Fprintln(os.Stderr, changeUsage())
522 fmt.Fprint(os.Stderr, renderHelpText(changeGroup))
529 523 return usagef("unknown change subcommand %q", sub)
530 524 }
531 525