Skip to content
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelog.d/1535.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
`pipx help COMMAND` can now be used as an alias for `pipx COMMAND --help`,
where COMMAND is a valid pipx command, or nothing.
1 change: 1 addition & 0 deletions src/pipx/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@
"pin",
"unpin",
"upgrade_interpreters",
"help",
]
2 changes: 2 additions & 0 deletions src/pipx/commands/help.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# The help command only reuses existing features
# This file exists to satisfy __all__ in pipx/commands/__init__.py
29 changes: 28 additions & 1 deletion src/pipx/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,15 @@ def run_pipx_command(args: argparse.Namespace, subparsers: Dict[str, argparse.Ar
return ExitCode(0)
elif args.command == "environment":
return commands.environment(value=args.value)
elif args.command == "help":
if args.subcommand is not None:
sys.argv[1] = args.subcommand
sys.argv[2] = "--help"
return cli()
else:
parser, _ = get_command_parser()
parser.print_help()
return ExitCode(0)
else:
raise PipxError(f"Unknown command {args.command}")

Expand Down Expand Up @@ -928,6 +937,21 @@ def _add_environment(subparsers: argparse._SubParsersAction, shared_parser: argp
p.add_argument("--value", "-V", metavar="VARIABLE", help="Print the value of the variable.")


def _add_help(subparsers: argparse._SubParsersAction, shared_parser: argparse.ArgumentParser) -> None:
p = subparsers.add_parser(
"help",
help="Print out help info for pipx or for a particular command (alias of --help).",
description="Print out help info for pipx or for a particular command (alias of --help).",
parents=[shared_parser],
)
p.add_argument(
"subcommand",
choices=commands.__all__,
nargs="?",
help="Print out help for the specified command, if provided, using pipx help COMMAND",
)


def get_command_parser() -> Tuple[argparse.ArgumentParser, Dict[str, argparse.ArgumentParser]]:
venv_container = VenvContainer(paths.ctx.venvs)

Expand Down Expand Up @@ -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"
Copy link
Contributor

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.

)

subparsers_with_subcommands = {}
_add_install(subparsers, shared_parser)
Expand All @@ -995,6 +1021,7 @@ def get_command_parser() -> Tuple[argparse.ArgumentParser, Dict[str, argparse.Ar
_add_runpip(subparsers, completer_venvs.use, shared_parser)
_add_ensurepath(subparsers, shared_parser)
_add_environment(subparsers, shared_parser)
_add_help(subparsers, shared_parser)

parser.add_argument("--version", action="store_true", help="Print version and exit")
subparsers.add_parser(
Expand Down