Mark required CLI flags in help output - #3585
Open
leopoldsedev wants to merge 1 commit into
Open
leopoldsedev wants to merge 1 commit into
leopoldsedev wants to merge 1 commit into
Conversation
Prefix mandatory options with (required) using existing Commander metadata while preserving standard help descriptions and annotations.
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.
Prefix mandatory options with (required) using existing Commander metadata while preserving standard help descriptions and annotations.
Human comments
What was wrong
bb <command> --helpgave no indication which options are mandatory. Commander already knows:.requiredOption()setsoption.mandatory, and the CLI relies on it to fail witherror: required option '--project <id>' not specified. But the default help formatter never reads that flag — it annotates defaults, choices, presets and env vars only. So the information existed and was simply not rendered, and the only way to discover a required flag was to run the command and read the error.What changed
apps/cli/src/index.ts: the root program now sets aconfigureHelp({ optionDescription })override that prefixes(required)to the description of any option withoption.mandatory, delegating toHelp.prototype.optionDescriptionfor the rest. Commander propagatesconfigureHelpto subcommands, so one override at the root covers every command group.The marker goes first so it stays scannable when descriptions wrap, and so it does not collide with Commander's trailing
(default: …)/(choices: …)annotations. Help text is otherwise untouched and there are no other behavioral changes.How you verified
Added
marks mandatory flags in help without marking optional flagstoapps/cli/src/__tests__/startup-graph.test.ts. It asserts the marker onbb thread spawn's--projectand--prompt, its absence on the optional--provider, and its absence onbb thread list's optional--project— so it catches both a missing marker and an over-eager one. The test matches on the flag plus the marker rather than on description wording, so it does not break when descriptions are reworded.mainwithout theindex.tschange (--projectmatcher fails), passes with it.npx vitest run src/__tests__/startup-graph.test.tsinapps/cli— 8 passed.turbo run typecheck --filter=@bb/cli— clean.bb thread spawn --help,bb thread list --help,bb --help.