diff options
author | Hans Ulrich Niedermann <hun@n-dimensional.de> | 2011-02-19 00:57:09 +0100 |
---|---|---|
committer | Hans Ulrich Niedermann <hun@n-dimensional.de> | 2011-02-19 00:57:09 +0100 |
commit | 9e8182ab53805a8bb214b3654fbd226b1b25b2d3 (patch) | |
tree | 0877fab745d045d558f1fb3cc4a2e7b79811a784 /src/fedpkg.py | |
parent | 4c5d0003ca3cace64ea780ca4121c46487b5899e (diff) | |
download | fedora-packager-9e8182ab53805a8bb214b3654fbd226b1b25b2d3.tar.gz fedora-packager-9e8182ab53805a8bb214b3654fbd226b1b25b2d3.tar.xz fedora-packager-9e8182ab53805a8bb214b3654fbd226b1b25b2d3.zip |
Add 'fedpkg help cmd' commandhelp-command-with-subcommands
Includes bash completion.
Diffstat (limited to 'src/fedpkg.py')
-rwxr-xr-x | src/fedpkg.py | 33 |
1 files changed, 28 insertions, 5 deletions
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', |