Issue #1535 - Add a help command (alias of --help)#1544
Issue #1535 - Add a help command (alias of --help)#1544
help command (alias of --help)#1544Conversation
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
Gitznik
left a comment
There was a problem hiding this comment.
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
|
|
||
| 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.
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.
Gitznik
left a comment
There was a problem hiding this comment.
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
Gitznik
left a comment
There was a problem hiding this comment.
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?
4279653 to
5cc32a6
Compare
gaborbernat
left a comment
There was a problem hiding this comment.
Can you rebase and fix the merge conflicts?
changelog.d/(if the patch affects the end users)Summary of changes
pipx --helpandpipx [command_name] --helpboth produce help info.helpsubcommand as an alias for--help#1535 requests a new pipx command that is an alias for--help.pipx helpandpipx 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!