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/index.go +14−4
| @@ -9,19 +9,29 @@ import ( | |||
| 9 | 9 | ||
| 10 | 10 | // ---------- index ---------- | |
| 11 | 11 | ||
| 12 | const indexUsage = `usage: vole admin index rebuild` | ||
| 12 | var indexGroup = &group{ | ||
| 13 | Name: "index", | ||
| 14 | Parent: "admin", | ||
| 15 | Summary: "rebuild the search index from the repositories", | ||
| 16 | Flags: []flagSpec{configFlag()}, | ||
| 17 | Subs: []subcommand{{ | ||
| 18 | Synopsis: "admin index rebuild", | ||
| 19 | Flags: []string{"config"}, | ||
| 20 | Notes: []string{"Rebuilds the index every search and listing reads. It is derived, so this\nrepairs it rather than losing anything. Local-only: it is not available over\n--remote."}, | ||
| 21 | }}, | ||
| 22 | } | ||
| 13 | 23 | ||
| 14 | 24 | func cmdIndex(args []string) error { | |
| 15 | f, err := parseFlags(args, configFlag()) | ||
| 25 | f, err := parseFlags(args, indexGroup.Flags...) | ||
| 16 | 26 | if err != nil { | |
| 17 | 27 | return err | |
| 18 | 28 | } | |
| 19 | 29 | if f.help { | |
| 20 | fmt.Fprintln(os.Stdout, indexUsage) | ||
| 30 | fmt.Fprint(os.Stdout, renderHelpText(indexGroup)) | ||
| 21 | 31 | return nil | |
| 22 | 32 | } | |
| 23 | 33 | if len(f.rest) != 1 || f.rest[0] != "rebuild" { | |
| 24 | fmt.Fprintln(os.Stderr, indexUsage) | ||
| 34 | fmt.Fprint(os.Stderr, renderHelpText(indexGroup)) | ||
| 25 | 35 | return usageErr{msg: "usage: vole admin index rebuild"} | |
| 26 | 36 | } | |
| 27 | 37 | st, err := forge.OpenPath(f.cfgPath) | |