-
Notifications
You must be signed in to change notification settings - Fork 430
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue #1535 - Add a help
command (alias of --help
)
#1544
base: main
Are you sure you want to change the base?
Conversation
Initial addition of a `commands/help.py` file Add "help" to `commands/__init__.py` to make pipx aware of a new command
Added an _add_help function which informs argparse of a "help" command, and an optional argument for it called "subcommand" Added a check for args.command == "help"
Reflects requirements set by the linter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution 💪 can you please add some tests for this?
Also can you verify this will work with commands with multiple subcommands, like pipx interpreter list
?
src/pipx/main.py
Outdated
@@ -973,7 +997,9 @@ def get_command_parser() -> Tuple[argparse.ArgumentParser, Dict[str, argparse.Ar | |||
) | |||
parser.man_short_description = PIPX_DESCRIPTION.splitlines()[1] # type: ignore[attr-defined] | |||
|
|||
subparsers = parser.add_subparsers(dest="command", description="Get help for commands with pipx COMMAND --help") | |||
subparsers = parser.add_subparsers( | |||
dest="command", description="Get help for commands with pipx COMMAND --help\n\t\t\t or pipx help COMMAND" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please stick to how the other commands wrap text in their description.
Example: `pipx help interpreter list` now has an identical output to `pipx interpreter list --help`
Thanks for your comment. I have added a fix for cases with multiple subcomamnds (e.g., |
The line `valid_commands = parser._subparsers._actions[4].choices.keys()` causes the linter to throw an error: ``` mypy.....................................................................Failed - hook id: mypy - exit code: 1 tests/test_help.py:23: error: Item "None" of "_ArgumentGroup | None" has no attribute "_actions" [union-attr] tests/test_help.py:23: error: Item "Iterable[Any]" of "Iterable[Any] | Any | None" has no attribute "keys" [union-attr] tests/test_help.py:23: error: Item "None" of "Iterable[Any] | Any | None" has no attribute "keys" [union-attr] Found 3 errors in 1 file (checked 76 source files) ``` All linter tests pass normally when that line is substituted with a hard-coded list of valid pipx commands.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally, looks fine for me. Please make all pipelines pass, I'll give it another proper review once that's done.
Rather than accessing a protected attribute of `parser._subparsers` Note: a commented out line with the protected access is still included in the event that the list of valid pipx commands changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just played around with this locally. If running pipx help
, the autocomplete does not work anymore unfortunately. Could you have a look at that please?
changelog.d/
(if the patch affects the end users)Summary of changes
pipx --help
andpipx [command_name] --help
both produce help info.help
subcommand as an alias for--help
#1535 requests a new pipx command that is an alias for--help
.pipx help
andpipx help [command_name]
can now be used to provide identical output to (1).Test plan
Tested by running
This is my first PR to a public repo. Please feel free to let me know if there are any guidelines or general tenets I've failed to follow. Thanks!