Repository navigation
fix(cli): require a subcommand in the CLI parser (#143) - #146
Merged
sergey-miryanov merged 2 commits intoSep 3, 2026
Merged
sergey-miryanov merged 2 commits into
sergey-miryanov merged 2 commits into
Conversation
Contributor
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #146 +/- ##
==========================================
+ Coverage 98.01% 98.25% +0.23%
==========================================
Files 60 60
Lines 3323 3317 -6
Branches 452 450 -2
==========================================
+ Hits 3257 3259 +2
+ Misses 39 33 -6
+ Partials 27 25 -2
🚀 New features to boost your workflow:
|
Owner
|
@mhaye9545 Could you please fix types in tests? |
Contributor
Author
|
Fixed! Replaced the inline lambda callbacks in est_main_subcommands_dispatch with explicit typed mock functions, so mypy (strict) passes cleanly with zero issues. |
Owner
|
Great! Thanks for your contribution! |
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.
Closes #143. Part of #142.
Summary
gcmonwith no subcommand used to print anAttributeErrortraceback ('Namespace' object has no attribute 'verbose'), whilegcmon 12345exited 2 with an invalid-choice message. This PR makes the subcommand mandatory in the argparse parser, which produces a consistent usage message for both cases, and deletes the dead fallback dispatch code inmain().Changes
src/gcmon/cli/main.py:_create_parser(), setrequired=Trueonparser.add_subparsers(dest="command", required=True, help="Available commands").src/gcmon/cli/main.py:main(), removedif hasattr(args, "func"), the dead fallbackif args.command is None, and thelogger.error("Unknown command: ...")block.return int(args.func(args))since all subparsers (monitor,combine,run) definefuncdefaults.logger = logging.getLogger("gcmon").tests/test_cli.py):test_main_no_subcommand_exits_2: assertsmain([])raisesSystemExitwithcode == 2and usage error naming the commands.test_main_invalid_subcommand_exits_2: assertsmain(["12345"])raisesSystemExitwithcode == 2and invalid-choice error.test_main_version_exits_0: assertsmain(["--version"])exits withcode == 0.test_main_subcommands_dispatch: pins thatmonitor,run, andcombinesubcommands dispatch to their handlers.## WIP->### Bugfixes.Verification
main([])exits 2 withgcmon: error: the following arguments are required: commandmain(["12345"])exits 2 withgcmon: error: argument command: invalid choice: '12345'main(["--version"])exits 0ruff check src testspasses cleanly.