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/flags_test.go +12−8
| @@ -18,14 +18,18 @@ func issueForTest() *metadata.Issue { | |||
| 18 | 18 | } | |
| 19 | 19 | } | |
| 20 | 20 | ||
| 21 | // issueSpecs is the subset of the issue table these parser tests exercise. The | ||
| 22 | // table itself is issueGroup.Flags, so a flag that is renamed or re-spelled is | ||
| 23 | // renamed here too. | ||
| 21 | 24 | func issueSpecs() []flagSpec { | |
| 22 | return []flagSpec{ | ||
| 23 | {long: "title", short: "t"}, | ||
| 24 | {long: "message", short: "m"}, | ||
| 25 | {long: "file", short: "F"}, | ||
| 26 | {long: "label", short: "l"}, | ||
| 27 | {long: "no-push", boolean: true}, | ||
| 25 | want := map[string]bool{"title": true, "message": true, "file": true, "label": true, "no-push": true} | ||
| 26 | var out []flagSpec | ||
| 27 | for _, s := range issueGroup.Flags { | ||
| 28 | if want[s.long] { | ||
| 29 | out = append(out, s) | ||
| 30 | } | ||
| 28 | 31 | } | |
| 32 | return out | ||
| 29 | 33 | } | |
| 30 | 34 | ||
| 31 | 35 | func TestFlagForms(t *testing.T) { | |
| @@ -246,10 +250,10 @@ func TestFlagsBelongToTheSubcommand(t *testing.T) { | |||
| 246 | 250 | if err != nil { | |
| 247 | 251 | t.Fatal(err) | |
| 248 | 252 | } | |
| 249 | if err := f.checkAllowed("vole issue close", "remote", "no-push"); err == nil || !isUsageErr(err) { | ||
| 253 | if err := f.checkAllowed("vole issue close"); err == nil || !isUsageErr(err) { | ||
| 250 | 254 | t.Fatalf("close with --title = %v, want a usage error", err) | |
| 251 | 255 | } | |
| 252 | if err := f.checkAllowed("vole issue new", "title", "message", "file", "label", "no-push"); err != nil { | ||
| 256 | if err := f.checkAllowed("vole issue new"); err != nil { | ||
| 253 | 257 | t.Fatalf("new with its own flags: %v", err) | |
| 254 | 258 | } | |
| 255 | 259 | } | |