help: filter by prefix, and document every command's arguments !129

merged merged by cmc on 2026-08-31 05:16 UTC · krz/gitbay:help-discoverability into main

Discussion

cmc

Closes #57.

Command.Summary carried prose and argument syntax joined by ": ", which left the syntax unreadable in a 149-line listing and unreachable from the CLI. It is split: Summary is prose, Usage is the argument syntax and opens with the command path.

Sixteen commands had no usage text at all. keys remove, pgp remove and register take arguments that were documented on no surface. They have Usage now, as does every other command, and TestEveryCommandDocumentsItsUsage keeps it that way: Usage must be present, must open with the command path, and the summary may not carry the syntax again.

help takes a prefix:

$ ssh git@gitbay.org help keys
keys add                 register an SSH public key (authorized_keys format)
  keys add [--scope full|git] < key.pub
keys list                list registered SSH keys
  keys list
keys remove              remove an SSH key by fingerprint
  keys remove <fingerprint>

The unfiltered listing is sorted, so a noun's commands sit together, and stays one line per command. An unmatched prefix exits 3.

help emits through emit(), so --json and the API return [{path, summary, usage}] rather than raw text. That changes one API behaviour: help used to fall through the envelope-or-wrap check in api.go and come back under output. The e2e case that covered wrapping used help for it and now uses repo download, which is still raw.

gitbay <cmd> --help asks the server for that command's usage instead of reprinting the one-line summary cobra holds. It costs a round trip, which matches every other CLI invocation.

Not covered here: gitbay issue --help still renders cobra's subcommand list without flags. Forwarding a group would need a name-to-prefix map for auth, which splits into keys, pgp, token and whoami. The two-step path works: group help, then gitbay issue create --help.

Full suite green.