From 9e8182ab53805a8bb214b3654fbd226b1b25b2d3 Mon Sep 17 00:00:00 2001 From: Hans Ulrich Niedermann Date: Sat, 19 Feb 2011 00:57:09 +0100 Subject: Add 'fedpkg help cmd' command Includes bash completion. --- src/fedpkg.py | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) (limited to 'src/fedpkg.py') diff --git a/src/fedpkg.py b/src/fedpkg.py index 9e78a28..adc0ab0 100755 --- a/src/fedpkg.py +++ b/src/fedpkg.py @@ -140,9 +140,26 @@ class TaskWatcher(object): else: return koji.TASK_STATES[info['state']].lower() -# Add a simple function to print usage, for the 'help' command -def usage(args, parser): - parser.print_help() +# Call this cmd_help() instead of just help() as the latter is a +# Python builtin function. +def cmd_help(args, parser, subparsers): + """\ + When 'fedpkg help' is called without an additional parameter, + print the fedpkg help message with a complete list of commands and + exit. + + When 'fedpkg help subcommand' is called with the 'subcommand' + parameter, print the help message for that subcommand and exit. + """ + subcmd = args.subcommand + if subcmd: + if subcmd in subparsers.choices: + command_subparser = subparsers.choices[subcmd] + command_subparser.print_help() + else: + print "Error: There is no such fedpkg subcommand like '%s'" % subcmd + else: + parser.print_help() # Define our stub functions def _is_secondary(module): @@ -889,8 +906,14 @@ def parse_cmdline(generate_manpage = False): # Set up the various actions # Add help to -h and --help - parser_help = subparsers.add_parser('help', help = 'Show usage') - parser_help.set_defaults(command = lambda args: usage(args, parser=parser)) + parser_help = subparsers.add_parser('help', + help = 'Print help on fedpkg or one of its subcommands', + formatter_class=argparse.RawDescriptionHelpFormatter, + description = textwrap.dedent(cmd_help.__doc__)) + parser_help.add_argument('subcommand', nargs='?', + help='the fedpkg subcommand to print help for') + parser_help.set_defaults(command = lambda args: cmd_help(args, parser=parser, + subparsers=subparsers)) # Add a common build parser to be used as a parent parser_build_common = subparsers.add_parser('build_common', -- cgit