diff options
author | Ryan Petrello <lists@ryanpetrello.com> | 2015-05-06 10:17:30 -0400 |
---|---|---|
committer | Ryan Petrello <lists@ryanpetrello.com> | 2015-05-06 10:17:56 -0400 |
commit | ca2e90a94031fdbba31bf4bda87b51a87e97eb7c (patch) | |
tree | fb7475ce51ddc4d8807900553d52eff682fe4f9e /cliff/help.py | |
parent | 79a8791e7fefdcbe62f264bf905ac09a1958e753 (diff) | |
download | cliff-master.tar.gz |
Diffstat (limited to 'cliff/help.py')
-rw-r--r-- | cliff/help.py | 80 |
1 files changed, 0 insertions, 80 deletions
diff --git a/cliff/help.py b/cliff/help.py deleted file mode 100644 index 9d96111..0000000 --- a/cliff/help.py +++ /dev/null @@ -1,80 +0,0 @@ -import argparse -import sys -import traceback - -from .command import Command - - -class HelpAction(argparse.Action): - """Provide a custom action so the -h and --help options - to the main app will print a list of the commands. - - The commands are determined by checking the CommandManager - instance, passed in as the "default" value for the action. - """ - def __call__(self, parser, namespace, values, option_string=None): - app = self.default - parser.print_help(app.stdout) - app.stdout.write('\nCommands:\n') - command_manager = app.command_manager - for name, ep in sorted(command_manager): - try: - factory = ep.load() - except Exception as err: - app.stdout.write('Could not load %r\n' % ep) - if namespace.debug: - traceback.print_exc(file=app.stdout) - continue - try: - cmd = factory(app, None) - except Exception as err: - app.stdout.write('Could not instantiate %r: %s\n' % (ep, err)) - if namespace.debug: - traceback.print_exc(file=app.stdout) - continue - one_liner = cmd.get_description().split('\n')[0] - app.stdout.write(' %-13s %s\n' % (name, one_liner)) - sys.exit(0) - - -class HelpCommand(Command): - """print detailed help for another command - """ - - def get_parser(self, prog_name): - parser = super(HelpCommand, self).get_parser(prog_name) - parser.add_argument('cmd', - nargs='*', - help='name of the command', - ) - return parser - - def take_action(self, parsed_args): - if parsed_args.cmd: - try: - the_cmd = self.app.command_manager.find_command( - parsed_args.cmd, - ) - cmd_factory, cmd_name, search_args = the_cmd - except ValueError: - # Did not find an exact match - cmd = parsed_args.cmd[0] - fuzzy_matches = [k[0] for k in self.app.command_manager - if k[0].startswith(cmd) - ] - if not fuzzy_matches: - raise - self.app.stdout.write('Command "%s" matches:\n' % cmd) - for fm in fuzzy_matches: - self.app.stdout.write(' %s\n' % fm) - return - cmd = cmd_factory(self.app, search_args) - full_name = (cmd_name - if self.app.interactive_mode - else ' '.join([self.app.NAME, cmd_name]) - ) - cmd_parser = cmd.get_parser(full_name) - else: - cmd_parser = self.get_parser(' '.join([self.app.NAME, 'help'])) - cmd_parser.print_help(self.app.stdout) - return 0 |