python (3.12.0)
1 from optparse import Values
2 from typing import List
3
4 from pip._internal.cli.base_command import Command
5 from pip._internal.cli.status_codes import SUCCESS
6 from pip._internal.exceptions import CommandError
7
8
9 class ESC[4;38;5;81mHelpCommand(ESC[4;38;5;149mCommand):
10 """Show help for commands"""
11
12 usage = """
13 %prog <command>"""
14 ignore_require_venv = True
15
16 def run(self, options: Values, args: List[str]) -> int:
17 from pip._internal.commands import (
18 commands_dict,
19 create_command,
20 get_similar_commands,
21 )
22
23 try:
24 # 'pip help' with no args is handled by pip.__init__.parseopt()
25 cmd_name = args[0] # the command we need help for
26 except IndexError:
27 return SUCCESS
28
29 if cmd_name not in commands_dict:
30 guess = get_similar_commands(cmd_name)
31
32 msg = [f'unknown command "{cmd_name}"']
33 if guess:
34 msg.append(f'maybe you meant "{guess}"')
35
36 raise CommandError(" - ".join(msg))
37
38 command = create_command(cmd_name)
39 command.parser.print_help()
40
41 return SUCCESS