import codecs as _codecs
import collections as _collections
+import functools as _functools
import inspect as _inspect
import locale as _locale
import logging as _logging
yield (id, tag)
+def _help(parser, command=None):
+ """
+ Show help for an nmbug command.
+
+ Because some folks prefer:
+
+ $ nmbug help COMMAND
+
+ to
+
+ $ nmbug COMMAND --help
+ """
+ if command:
+ parser.parse_args([command, '--help'])
+ else:
+ parser.parse_args(['--help'])
+
+
if __name__ == '__main__':
import argparse
help='Log verbosity. Defaults to {!r}.'.format(
_logging.getLevelName(_LOG.level).lower()))
+ help = _functools.partial(_help, parser=parser)
+ help.__doc__ = _help.__doc__
subparsers = parser.add_subparsers(
title='commands',
description=(
'clone',
'commit',
'fetch',
+ 'help',
'log',
'merge',
'pull',
'Override the default configured in branch.<name>.remote '
'to fetch from a particular remote repository (e.g. '
"'origin')."))
+ elif command == 'help':
+ subparser.add_argument(
+ 'command', metavar='COMMAND', nargs='?',
+ help='The command to show help for.')
elif command == 'log':
subparser.add_argument(
'args', metavar='ARG', nargs='*',
parser.print_usage()
_sys.exit(1)
- (arg_names, varargs, varkw) = _inspect.getargs(args.func.__code__)
+ if args.func == help:
+ arg_names = ['command']
+ else:
+ (arg_names, varargs, varkw) = _inspect.getargs(args.func.__code__)
kwargs = {key: getattr(args, key) for key in arg_names if key in args}
try:
args.func(**kwargs)