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/issue.go +48−59
| @@ -12,82 +12,71 @@ import ( | |||
| 12 | 12 | "rodent.software/vole/metadata" | |
| 13 | 13 | ) | |
| 14 | 14 | ||
| 15 | func issueUsage() string { | ||
| 16 | return `usage: vole issue new --title <title> [-m <text> | -F <file>] [-l <label>]... [-a <account>]... | ||
| 17 | or: vole issue comment <id> [-m <text> | -F <file>] [--reply-to <comment-id>] | ||
| 18 | or: vole issue edit-comment <id> <comment-id> [-m <text> | -F <file>] | ||
| 19 | or: vole issue rm-comment <id> <comment-id> | ||
| 20 | or: vole issue edit <id> [--title <title>] [-m <text> | -F <file>] [-l <label>]... | ||
| 21 | [-a <account>]... [--unassign <account>]... | ||
| 22 | or: vole issue assign <id> <account>... | ||
| 23 | or: vole issue unassign <id> <account>... | ||
| 24 | or: vole issue close <id> | ||
| 25 | or: vole issue reopen <id> | ||
| 26 | or: vole issue list [--state <state>] [-l <label>]... [--assignee <account>]... [--format <fmt>] | ||
| 27 | or: vole issue show <id> | ||
| 28 | |||
| 29 | Multiple -l, -a and --assignee options are allowed. --format understands | ||
| 30 | %(number), %(id), %(shortid), %(state), %(author), %(title), %(labels), | ||
| 31 | %(assignees) and %(created). A comment id takes a prefix. An issue id takes a | ||
| 32 | prefix or the #42 number: numbers are one sequence shared with change | ||
| 33 | requests, oldest first. Deleting a comment leaves the text in git; only its | ||
| 34 | author (or an admin, audited) can edit or delete it.` | ||
| 15 | var issueGroup = &group{ | ||
| 16 | Name: "issue", | ||
| 17 | Summary: "file, comment on, edit, and close issues", | ||
| 18 | Flags: []flagSpec{ | ||
| 19 | {long: "title", short: "t", arg: "<title>", desc: "the issue title"}, | ||
| 20 | {long: "message", short: "m", arg: "<text>", desc: "the body text; an alternative to -F"}, | ||
| 21 | {long: "file", short: "F", arg: "<file|->", desc: "read the body from a file; - reads standard input"}, | ||
| 22 | {long: "reply-to", arg: "<comment-id>", desc: "the comment this one replies to"}, | ||
| 23 | {long: "label", short: "l", arg: "<label>", desc: "a label to add; repeatable"}, | ||
| 24 | {long: "assign", short: "a", arg: "<account>", desc: "an account to assign; repeatable"}, | ||
| 25 | {long: "unassign", arg: "<account>", desc: "an account to remove from the assignees; repeatable"}, | ||
| 26 | {long: "assignee", arg: "<account>", desc: "only issues assigned to this account; repeatable"}, | ||
| 27 | {long: "state", arg: "<state>", desc: "open, closed, or all (default open)"}, | ||
| 28 | {long: "remote", arg: "<name>", desc: "the remote naming the instance (default origin)"}, | ||
| 29 | {long: "format", arg: "<fmt>", desc: "a template such as '%(number) %(title)'"}, | ||
| 30 | {long: "no-push", boolean: true, desc: "commit locally without pushing"}, | ||
| 31 | }, | ||
| 32 | Subs: []subcommand{ | ||
| 33 | {Name: "new", Synopsis: "issue new --title <title> [-m <text> | -F <file>] [-l <label>]... [-a <account>]...", Flags: []string{"title", "message", "file", "label", "assign", "remote", "no-push"}}, | ||
| 34 | {Name: "comment", Synopsis: "issue comment <id> [-m <text> | -F <file>] [--reply-to <comment-id>]", Flags: []string{"message", "file", "reply-to", "remote", "no-push"}}, | ||
| 35 | {Name: "edit-comment", Synopsis: "issue edit-comment <id> <comment-id> [-m <text> | -F <file>]", Flags: []string{"message", "file", "remote", "no-push"}}, | ||
| 36 | {Name: "rm-comment", Synopsis: "issue rm-comment <id> <comment-id>", Flags: []string{"remote", "no-push"}}, | ||
| 37 | {Name: "edit", Synopsis: "issue edit <id> [--title <title>] [-m <text> | -F <file>] [-l <label>]... [-a <account>]... [--unassign <account>]...", Flags: []string{"title", "message", "file", "label", "assign", "unassign", "remote", "no-push"}}, | ||
| 38 | {Name: "assign", Synopsis: "issue assign <id> <account>...", Flags: []string{"remote", "no-push"}}, | ||
| 39 | {Name: "unassign", Synopsis: "issue unassign <id> <account>...", Flags: []string{"remote", "no-push"}}, | ||
| 40 | {Name: "close", Synopsis: "issue close <id>", Flags: []string{"remote", "no-push"}}, | ||
| 41 | {Name: "reopen", Synopsis: "issue reopen <id>", Flags: []string{"remote", "no-push"}}, | ||
| 42 | {Name: "list", Synopsis: "issue list [--state <state>] [-l <label>]... [--assignee <account>]... [--format <fmt>]", Flags: []string{"state", "label", "assignee", "format", "remote"}, Notes: []string{"`--format` understands `%(number)`, `%(id)`, `%(shortid)`, `%(state)`, `%(author)`, `%(title)`, `%(labels)`, `%(assignees)` and `%(created)`."}}, | ||
| 43 | {Name: "show", Synopsis: "issue show <id>", Flags: []string{"remote"}}, | ||
| 44 | }, | ||
| 45 | Notes: []string{ | ||
| 46 | "Multiple `-l`, `-a` and `--assignee` options are allowed. A comment id takes a\n" + | ||
| 47 | "prefix. An issue id takes a prefix or the #42 number: numbers are one sequence\n" + | ||
| 48 | "shared with change requests, oldest first.", | ||
| 49 | "Deleting a comment leaves the text in git; only its author (or an admin, audited)\n" + | ||
| 50 | "can edit or delete it.", | ||
| 51 | }, | ||
| 52 | See: []seeAlso{{"Issues", "issues.md"}}, | ||
| 35 | 53 | } | |
| 36 | 54 | ||
| 37 | 55 | func cmdIssue(args []string) error { | |
| 38 | 56 | if len(args) == 0 { | |
| 39 | fmt.Fprint(os.Stderr, issueUsage()+"\n") | ||
| 57 | fmt.Fprint(os.Stderr, renderHelpText(issueGroup)) | ||
| 40 | 58 | return usageErr{msg: "no issue subcommand given"} | |
| 41 | 59 | } | |
| 42 | 60 | if args[0] == "-h" || args[0] == "--help" || args[0] == "help" { | |
| 43 | fmt.Fprintln(os.Stdout, issueUsage()) | ||
| 61 | fmt.Fprint(os.Stdout, renderHelpText(issueGroup)) | ||
| 44 | 62 | return nil | |
| 45 | 63 | } | |
| 46 | 64 | sub := args[0] | |
| 47 | specs := []flagSpec{ | ||
| 48 | {long: "title", short: "t"}, | ||
| 49 | {long: "message", short: "m"}, | ||
| 50 | {long: "file", short: "F"}, | ||
| 51 | {long: "reply-to"}, | ||
| 52 | {long: "label", short: "l"}, | ||
| 53 | {long: "assign", short: "a"}, | ||
| 54 | {long: "unassign"}, | ||
| 55 | {long: "assignee"}, | ||
| 56 | {long: "state"}, | ||
| 57 | {long: "remote"}, | ||
| 58 | {long: "format"}, | ||
| 59 | {long: "no-push", boolean: true}, | ||
| 60 | } | ||
| 61 | f, err := parseFlags(args[1:], specs...) | ||
| 65 | f, err := parseFlags(args[1:], issueGroup.Flags...) | ||
| 62 | 66 | if err != nil { | |
| 63 | 67 | return err | |
| 64 | 68 | } | |
| 65 | 69 | if f.help { | |
| 66 | fmt.Fprintln(os.Stdout, issueUsage()) | ||
| 70 | fmt.Fprint(os.Stdout, renderHelpText(issueGroup)) | ||
| 67 | 71 | return nil | |
| 68 | 72 | } | |
| 69 | issueFlags := map[string][]string{ | ||
| 70 | "new": {"title", "message", "file", "label", "assign", "remote", "no-push"}, | ||
| 71 | "comment": {"message", "file", "reply-to", "remote", "no-push"}, | ||
| 72 | "edit-comment": {"message", "file", "remote", "no-push"}, | ||
| 73 | "rm-comment": {"remote", "no-push"}, | ||
| 74 | "edit": {"title", "message", "file", "label", "assign", "unassign", "remote", "no-push"}, | ||
| 75 | "assign": {"remote", "no-push"}, | ||
| 76 | "unassign": {"remote", "no-push"}, | ||
| 77 | "close": {"remote", "no-push"}, | ||
| 78 | "reopen": {"remote", "no-push"}, | ||
| 79 | "list": {"state", "label", "assignee", "format", "remote"}, | ||
| 80 | "show": {"remote"}, | ||
| 81 | } | ||
| 82 | if names, ok := issueFlags[sub]; ok { | ||
| 83 | if err := f.checkAllowed("vole issue "+sub, names...); err != nil { | ||
| 84 | return err | ||
| 85 | } | ||
| 86 | } else { | ||
| 87 | fmt.Fprint(os.Stderr, issueUsage()+"\n") | ||
| 73 | if !hasSubcommand("issue", sub) { | ||
| 74 | fmt.Fprint(os.Stderr, renderHelpText(issueGroup)) | ||
| 88 | 75 | return usagef("unknown issue subcommand %q", sub) | |
| 89 | 76 | } | |
| 90 | |||
| 77 | if err := f.checkAllowed("vole issue " + sub); err != nil { | ||
| 78 | return err | ||
| 79 | } | ||
| 91 | 80 | c, err := client.NewBranch(f.one("remote"), metadata.Ref) | |
| 92 | 81 | if err != nil { | |
| 93 | 82 | return err | |
| @@ -454,7 +443,7 @@ func cmdIssue(args []string) error { | |||
| 454 | 443 | } | |
| 455 | 444 | return fmt.Errorf("no issue matching %q", id) | |
| 456 | 445 | } | |
| 457 | fmt.Fprint(os.Stderr, issueUsage()+"\n") | ||
| 446 | fmt.Fprint(os.Stderr, renderHelpText(issueGroup)) | ||
| 458 | 447 | return usagef("unknown issue subcommand %q", sub) | |
| 459 | 448 | } | |
| 460 | 449 | ||