Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 19EE1431FC0 for ; Fri, 3 Oct 2014 11:21:15 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" X-Spam-Flag: NO X-Spam-Score: -0.1 X-Spam-Level: X-Spam-Status: No, score=-0.1 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_NONE=-0.0001] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id YE-tOzpSDU84 for ; Fri, 3 Oct 2014 11:21:07 -0700 (PDT) Received: from resqmta-po-07v.sys.comcast.net (resqmta-po-07v.sys.comcast.net [96.114.154.166]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id BBFB8431FB6 for ; Fri, 3 Oct 2014 11:21:07 -0700 (PDT) Received: from resomta-po-19v.sys.comcast.net ([96.114.154.243]) by resqmta-po-07v.sys.comcast.net with comcast id yiLt1o0055FMDhs01iM7D0; Fri, 03 Oct 2014 18:21:07 +0000 Received: from odin.tremily.us ([24.18.63.50]) by resomta-po-19v.sys.comcast.net with comcast id yiM51o00E152l3L01iM517; Fri, 03 Oct 2014 18:21:06 +0000 Received: by odin.tremily.us (Postfix, from userid 1000) id 2699413EA33C; Fri, 3 Oct 2014 11:21:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tremily.us; s=odin; t=1412360465; bh=YDCxxJ0z1/HH/7VyFCX5nYITv+PceEvVcAIWv6EhQYI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:In-Reply-To: References; b=kY3LsZURnKTY2cLjcboWsEE8BScVKgNgYPsAdI6ElwaiOjhZC9wwBS+PYk4cRLj5T Mxt2OY2d5NJ0aMkbtXJVz7vIuBYR0Kk4uXy59SKVZfHUUqL8LTQQt9jnK5fpM1oRjW ndNg+JAWaiY2EaNBrwHDW3UwKooSHIt3PPqqjSZo= From: "W. Trevor King" To: notmuch@notmuchmail.org Subject: [PATCH v6 2/2] nmbug: Add a 'help' command for folks who don't like --help Date: Fri, 3 Oct 2014 11:20:58 -0700 Message-Id: <0a4f023f734b5c59ff3b3577961f679d141c3c74.1412359989.git.wking@tremily.us> X-Mailer: git-send-email 2.0.4 In-Reply-To: References: In-Reply-To: References: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net; s=q20140121; t=1412360467; bh=8rEqzVyY3jed6cjDeAUf2BedGIrbtJReNs8jlFb+B2E=; h=Received:Received:Received:From:To:Subject:Date:Message-Id; b=VUR9gWN6VH6BZ85N7dYxe+ZLD5MZAhn1rPlkHC0F9l+qVWIvZC3WUWfPuXS7fHepd qHXgzi7V2Vb2sADFNKGrtTzGDvOZrxxlPUjukqGQtJLKSGcJHaGWEu+JN3hpqhD92L mKx5Gp8lcVscGhxaRyzRpqcc4UP/ruNaUXxzbRxHOZWRrW+wQTMc4FM3UvU/23Cdrf RxzaHiuI4hNLp8Toh+iYkUXlIpnIfyKHXDLvzgs9CVGEKLB1NJJF2jSqwPemarmj/n yTw7ue1sBiRt+beQtiU9N2qA+oxDlvZEB9YV5VTlkrNmBo/Rb8g7QQAcWOKHyz91Vv zVeBjuwWcw5PA== Cc: Tomi Ollila , David Bremner X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 03 Oct 2014 18:21:15 -0000 The 'if args.func == help' block at the end avoids: AttributeError: 'functools.partial' object has no attribute '__code__' --- devel/nmbug/nmbug | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/devel/nmbug/nmbug b/devel/nmbug/nmbug index 9402ead..932ec12 100755 --- a/devel/nmbug/nmbug +++ b/devel/nmbug/nmbug @@ -32,6 +32,7 @@ from __future__ import unicode_literals import codecs as _codecs import collections as _collections +import functools as _functools import inspect as _inspect import locale as _locale import logging as _logging @@ -677,6 +678,24 @@ def _unpack_diff_lines(stream): 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 @@ -692,6 +711,8 @@ if __name__ == '__main__': 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=( @@ -703,6 +724,7 @@ if __name__ == '__main__': 'clone', 'commit', 'fetch', + 'help', 'log', 'merge', 'pull', @@ -746,6 +768,10 @@ if __name__ == '__main__': 'Override the default configured in branch..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='*', @@ -796,7 +822,10 @@ if __name__ == '__main__': 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) -- 2.1.0.60.g85f0837