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/admin.go +14−23

@@ -10,26 +10,17 @@ import (
10 10 "rodent.software/vole/client"
11 11 )
12 12
13 const adminUsage = `usage: vole admin [--remote <name|ssh-url>] [--config <path>] [--json] <command>...
14
15 Server management:
16 init [--dir <path>]
17 account create [--key <file|->] [--role <role>] [--bot] <name>
18 create an account, with a key or a passkey invite
19 account invite <name> print a fresh one-time enrollment link
20 account credentials|rm-credential <name> [credential-id]
21 account sessions <name>
22 account revoke-sessions [--all | <name>]
23 account add-key|rm-key|retire|role|grant-admin|revoke-admin|show|list|backup
24 repo create|rename|delete|list
25 acl show|set-role|set-default-role|set-approvals|checks|protect|runners
26 gc [--dry-run] [--grace <duration>]
27 index rebuild
28
29 With --remote, the command runs on the instance over SSH and must be run by an
30 instance admin. --json prints the server's JSON response instead of text.
31 --remote accepts a Git remote name or an instance URL such as
32 ssh://git@forge.example.com:2222`
13 var adminGroup = &group{
14 Name: "admin",
15 Summary: "server management: accounts, repositories, access, and maintenance",
16 Banner: "admin [--remote <name|ssh-url>] [--config <path>] [--json] <command>...",
17 Flags: []flagSpec{
18 {long: "remote", arg: "<name|ssh-url>", desc: "run the command on the instance this remote names, as an instance admin"},
19 {long: "config", arg: "<path>", desc: "the vole.toml to read; local only, and refused with --remote"},
20 {long: "json", boolean: true, desc: "print the server's JSON response instead of text (needs --remote)"},
21 },
22 See: []seeAlso{{"Accounts and access § Remote administration", "accounts-and-access.md#remote-administration"}},
23 }
33 24
34 25 // cmdAdmin is the single namespace for server management. Without --remote the
35 26 // command runs against the local vole.toml; with it, the same command is sent to
@@ -40,11 +31,11 @@ func cmdAdmin(args []string) error {
40 31 return err
41 32 }
42 33 if len(rest) == 0 {
43 fmt.Fprintln(os.Stderr, adminUsage)
34 fmt.Fprint(os.Stderr, renderHelpText(adminGroup))
44 35 return usageErr{msg: "no admin command given"}
45 36 }
46 37 if rest[0] == "-h" || rest[0] == "--help" || rest[0] == "help" {
47 fmt.Fprintln(os.Stdout, adminUsage)
38 fmt.Fprint(os.Stdout, renderHelpText(adminGroup))
48 39 return nil
49 40 }
50 41
@@ -56,7 +47,7 @@ func cmdAdmin(args []string) error {
56 47 return usagef("%s is not available over --remote", resource)
57 48 }
58 49 default:
59 fmt.Fprintln(os.Stderr, adminUsage)
50 fmt.Fprint(os.Stderr, renderHelpText(adminGroup))
60 51 return usagef("unknown admin command %q", resource)
61 52 }
62 53