refactor(benchmarks): subcommand-scoped CLI flags via subparsers#149
Merged
Conversation
The flat parser hung every flag off one positional command, so `run --markdown` (and other cross-command flag misuse) parsed and silently no-oped. Split into `run`/`check` subparsers owning their own flags, so a misplaced flag is an argparse error. Extract _build_parser() and give main(argv=None) an optional argv so the grammar is unit-testable without Postgres. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Benchmark gate✅ gate passed
Gated (fails the build): |
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.
What
The
benchmarksCLI registeredcommandas one positional withchoicesand hung every flag (--messages,--repeats,--write-baseline,--markdown) on the single top-level parser. argparse accepted any flag with either command, but each flag is read by only one — sopython -m benchmarks run --markdownparsed and silently did nothing.Split into real
run/checksubparsers, each owning its own flags. Misplaced flags now error at parse time (error: unrecognized arguments: --markdown, exit 2).How
_build_parser()builds the two subparsers (run:--messages/--repeats/--write-baseline;check:--markdown); dispatch staysif args.command == "check".main(argv=None)takes an optional argv so the grammar is unit-testable without spinning up Postgres.justrecipes use (run …,check,check --markdown).Testing
run --markdownandcheck --write-baselineraiseSystemExit;check --markdown/run --messages … --write-baselineparse to the right namespace; a subcommand is required. 20/20 intests/test_benchmarks.pypass; ruff + ty clean.python -m benchmarks run --markdownexits 2;--helplists therun/checksubcommands.Design: planning/changes/2026-07-17.04-benchmarks-cli-subparsers.md
🤖 Generated with Claude Code