fix/help: Generate help command list from registered commands - #1377
Open
marcleblanc2 wants to merge 1 commit into
Open
fix/help: Generate help command list from registered commands#1377marcleblanc2 wants to merge 1 commit into
marcleblanc2 wants to merge 1 commit into
Conversation
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>
This was referenced Sep 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of FE-502. Stacked on #1376 (which is stacked on #1375); retarget to
mainonce those merge. Only the last commit is new here.Problem
The "The commands are:" block in
src helpwas a hand-maintained string incmd/src/main.go, and it had drifted from the registered commands:src debug(added 2022),src snapshot(2022) andsrc lsp(2026) were never added to it.codeownerswas described as "manages code ownership information" in help but "manages ingested code ownership data" in the command itself.src docskippeddocandpublishby hard-coded name;publishno longer exists.Nothing checked that
src help,src doc, and the registered commands agreed. #1375 fixed thesrc docside of the drift; this PR makes it impossible for the three lists to diverge again.Change
cmd/src/help.go:rootCommands()merges the legacycommandsregistry and the urfave/climigratedCommandsregistry into one sorted list;usageText()renders the help from it.main.goloses the 55-line constant.commandstruct gainsdescription(one-liner for help) andhidden(excluded from help and fromsrc doc). Every top-level legacy command gets a description;docis marked hidden anddoc.gouses the flag instead of the hard-coded names.version(urfave/cli) gets aUsage, so it has a description like every other migrated command. Side effect:version.mdfromsrc docgains that one-line summary (only generated-content change; file set is unchanged at 77).orgs manages organizations (alias: org)) rather than in the name column, becausebatchhas five aliases and listing them in the column made it 65 characters wide.Rendered:
Tests: help ⇔ registered commands ⇔ generated docs
cmd/src/help_test.gocomputes the expected command set directly from the two registries (independently ofrootCommands()), then:TestHelpListsAllRegisteredCommands: the parsedsrc helplist 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:TestDocRootIndexMatchesHelpreplacesTestDocRootIndexListsAllCommandsand asserts thesrc docrootindex.mdlinks exactly the registered set and exactly thesrc helpset (both directions). Together withTestDocGeneratesExpectedFiles(golden 77-file list mirroringOUTPUT_FILESin sourcegraph/sourcegraph) andTestDocLegacyGroupsHaveSubcommandPagesfrom #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.shmirrorsdoc/cli/referencesinto 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:
lspfromrootCommands()→TestHelpListsAllRegisteredCommandsandTestDocRootIndexMatchesHelpfail listinglspUsagefromversion→TestRootCommandsAreWellFormed:command "version" has no descriptionmaps.Copyargument swap →TestDocRootIndexMatchesHelpfails listing all legacy commandsTest plan
go test ./cmd/src/...passes.go run ./cmd/src helprenders the list above;go run ./cmd/src version -hshows the new NAME line.go run ./cmd/src doc -o /tmp/xvs. the chore: Remove deprecatedsrc teamscommands #1376 output: same 77 files, onlyversion.mddiffers (adds the summary line).