summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHans Ulrich Niedermann <hun@n-dimensional.de>2011-02-19 00:57:09 +0100
committerHans Ulrich Niedermann <hun@n-dimensional.de>2011-02-19 00:57:09 +0100
commit9e8182ab53805a8bb214b3654fbd226b1b25b2d3 (patch)
tree0877fab745d045d558f1fb3cc4a2e7b79811a784
parent4c5d0003ca3cace64ea780ca4121c46487b5899e (diff)
downloadfedora-packager-help-command-with-subcommands.zip
fedora-packager-help-command-with-subcommands.tar.gz
fedora-packager-help-command-with-subcommands.tar.xz
Add 'fedpkg help cmd' commandhelp-command-with-subcommands
Includes bash completion.
-rw-r--r--src/fedpkg.bash6
-rwxr-xr-xsrc/fedpkg.py33
2 files changed, 33 insertions, 6 deletions
diff --git a/src/fedpkg.bash b/src/fedpkg.bash
index 2d0f4d8..ea8fffd 100644
--- a/src/fedpkg.bash
+++ b/src/fedpkg.bash
@@ -93,7 +93,7 @@ _fedpkg()
local after= after_more=
case $command in
- help|clog|gimmespec|giturl|lint|mockbuild|new|push|unused-patches|update|verrel)
+ clog|gimmespec|giturl|lint|mockbuild|new|push|unused-patches|update|verrel)
;;
build)
options="--nowait --background --skip-tag --scratch"
@@ -130,6 +130,9 @@ _fedpkg()
after="file"
after_more=true
;;
+ help)
+ after="command"
+ ;;
import)
options="--create"
options_branch="--branch"
@@ -241,6 +244,7 @@ _fedpkg()
case $after in
file) _filedir_exclude_paths; compgen_extra=${COMPREPLY[@]} ;;
srpm) _filedir_exclude_paths "*.src.rpm"; compgen_extra=${COMPREPLY[@]} ;;
+ command) compgen_extra="${commands}" ;;
branch) after_options="$(_fedpkg_branch "$path")" ;;
package) after_options="$(_fedpkg_package "$cur")";;
esac
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',