Skip to content

fix/help: Generate help command list from registered commands - #1377

Open
marcleblanc2 wants to merge 1 commit into
remove-teams-commandfrom
help-from-registered-commands
Open

fix/help: Generate help command list from registered commands#1377
marcleblanc2 wants to merge 1 commit into
remove-teams-commandfrom
help-from-registered-commands

Conversation

@marcleblanc2

@marcleblanc2 marcleblanc2 commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Part of FE-502. Stacked on #1376 (which is stacked on #1375); retarget to main once those merge. Only the last commit is new here.

Problem

The "The commands are:" block in src help was a hand-maintained string in cmd/src/main.go, and it had drifted from the registered commands:

  • src debug (added 2022), src snapshot (2022) and src lsp (2026) were never added to it.
  • codeowners was described as "manages code ownership information" in help but "manages ingested code ownership data" in the command itself.
  • src doc skipped doc and publish by hard-coded name; publish no longer exists.

Nothing checked that src help, src doc, and the registered commands agreed. #1375 fixed the src doc side of the drift; this PR makes it impossible for the three lists to diverge again.

Change

  • New cmd/src/help.go: rootCommands() merges the legacy commands registry and the urfave/cli migratedCommands registry into one sorted list; usageText() renders the help from it. main.go loses the 55-line constant.
  • Legacy command struct gains description (one-liner for help) and hidden (excluded from help and from src doc). Every top-level legacy command gets a description; doc is marked hidden and doc.go uses the flag instead of the hard-coded names.
  • version (urfave/cli) gets a Usage, so it has a description like every other migrated command. Side effect: version.md from src doc gains that one-line summary (only generated-content change; file set is unchanged at 77).
  • Aliases are now shown after the description (orgs manages organizations (alias: org)) rather than in the name column, because batch has five aliases and listing them in the column made it 65 characters wide.

Rendered:

The commands are:

	abc          manages agentic batch changes
	api          interacts with the Sourcegraph GraphQL API
	auth         authentication helper commands
	batch        manages batch changes (alias: batchchange, batch-change, batchchanges, batch-changes, batches)
	code-intel   manages code intelligence data
	codeowners   manages ingested code ownership data (alias: codeowner)
	config       manages global, org, and user settings
	debug        gathers and bundles debug data from a Sourcegraph deployment for troubleshooting
	extsvc       manages external services (alias: external-service)
	login        authenticate to a Sourcegraph instance with your user credentials
	lsp          runs a Language Server Protocol server that proxies requests to Sourcegraph code intelligence
	orgs         manages organizations (alias: org)
	repos        manages repositories (alias: repo)
	search       search for results on Sourcegraph
	search-jobs  manages search jobs (alias: search-job)
	serve-git    serves your local git repositories over HTTP for Sourcegraph to pull (alias: servegit)
	snapshot     manages snapshots of Sourcegraph instance databases (EXPERIMENTAL)
	users        manages users (alias: user)
	version      display and compare the src-cli version against the recommended version for your instance

Tests: help ⇔ registered commands ⇔ generated docs

cmd/src/help_test.go computes the expected command set directly from the two registries (independently of rootCommands()), then:

  • TestHelpListsAllRegisteredCommands: the parsed src help list equals that set.
  • TestRootCommandsAreWellFormed: every visible command has a description; no duplicate names; no alias collides with a name.
  • TestHelpHidesHiddenCommands, TestFormatCommandList.

cmd/src/doc_test.go: TestDocRootIndexMatchesHelp replaces TestDocRootIndexListsAllCommands and asserts the src doc root index.md links exactly the registered set and exactly the src help set (both directions). Together with TestDocGeneratesExpectedFiles (golden 77-file list mirroring OUTPUT_FILES in sourcegraph/sourcegraph) and TestDocLegacyGroupsHaveSubcommandPages from #1375, a new command that is registered but missing from help or from the docs fails CI.

The third leg, "copied into the doc site", is sourcegraph/sourcegraph#15529: _generated.push.sh mirrors doc/cli/references into sourcegraph/docs instead of copying over it, so removed commands disappear from the site instead of lingering.

Mutation checks I ran locally, each caught by the named test:

  • drop lsp from rootCommands()TestHelpListsAllRegisteredCommands and TestDocRootIndexMatchesHelp fail listing lsp
  • remove Usage from versionTestRootCommandsAreWellFormed: command "version" has no description
  • reintroduce the maps.Copy argument swap → TestDocRootIndexMatchesHelp fails listing all legacy commands

Test plan

  • go test ./cmd/src/... passes.
  • go run ./cmd/src help renders the list above; go run ./cmd/src version -h shows the new NAME line.
  • go run ./cmd/src doc -o /tmp/x vs. the chore: Remove deprecated src teams commands #1376 output: same 77 files, only version.md differs (adds the summary line).

The "The commands are:" block in 'src help' was a hand-maintained string in
main.go. It had drifted from the registered commands: 'debug', 'snapshot',
and 'lsp' were never added, and the codeowners description differed from
the command's own Usage.

Build the list at runtime from both registries (legacy 'commands' and
urfave/cli 'migratedCommands'). Legacy commands get a 'description' field
and a 'hidden' flag; 'src doc' uses the same flag instead of hard-coding
the names to skip. 'version' gets a Usage so it has a description.

Tests keep the three lists apples-to-apples:
- 'src help' == registered commands (TestHelpListsAllRegisteredCommands)
- 'src doc' root index == 'src help' == registered (TestDocRootIndexMatchesHelp)
- every visible command has a description (TestRootCommandsAreWellFormed)

Amp-Thread-ID: https://ampcode.com/threads/T-01a08410-86ca-72be-9928-2810e837fae1
Co-authored-by: Amp <amp@ampcode.com>
@marcleblanc2 marcleblanc2 changed the title help: generate the 'src help' command list from the registered commands, and test help == docs fix/help: Generate help command list from registered commands Sep 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant