help.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # The following comment should be removed at some point in the future.
  2. # mypy: disallow-untyped-defs=False
  3. from __future__ import absolute_import
  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. class HelpCommand(Command):
  8. """Show help for commands"""
  9. usage = """
  10. %prog <command>"""
  11. ignore_require_venv = True
  12. def run(self, options, args):
  13. from pip._internal.commands import (
  14. commands_dict, create_command, get_similar_commands,
  15. )
  16. try:
  17. # 'pip help' with no args is handled by pip.__init__.parseopt()
  18. cmd_name = args[0] # the command we need help for
  19. except IndexError:
  20. return SUCCESS
  21. if cmd_name not in commands_dict:
  22. guess = get_similar_commands(cmd_name)
  23. msg = ['unknown command "%s"' % cmd_name]
  24. if guess:
  25. msg.append('maybe you meant "%s"' % guess)
  26. raise CommandError(' - '.join(msg))
  27. command = create_command(cmd_name)
  28. command.parser.print_help()
  29. return SUCCESS