From f47353e7efef1162e3222ff3767c7cba248e333f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johann=20Kl=C3=A4hn?= Date: Fri, 21 Mar 2014 22:12:15 +0100 Subject: [PATCH] accept names of other commands in help command --- attic/archiver.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/attic/archiver.py b/attic/archiver.py index b33abc4a7..584d1c4ca 100644 --- a/attic/archiver.py +++ b/attic/archiver.py @@ -2,6 +2,7 @@ import argparse from binascii import hexlify from datetime import datetime from operator import attrgetter +import functools import io import os import stat @@ -385,13 +386,15 @@ Type "Yes I am sure" if you understand this and want to continue.\n""") $ attic create -e /home/user/cache/ repo.attic / /home/user/cache/important ''' - def do_help(self, args): - if args.topic in self.helptext: + def do_help(self, parser, commands, args): + if not args.topic: + parser.print_help() + elif args.topic in self.helptext: print(self.helptext[args.topic]) + elif args.topic in commands: + commands[args.topic].print_help() else: - # FIXME: If topic is one of the regular commands, show that help. - # Otherwise, show the default global help. - print('No help available on %s' % (args.topic,)) + parser.error('No help available on %s' % (args.topic,)) return self.exit_code def preprocess_args(self, args): @@ -619,8 +622,9 @@ Type "Yes I am sure" if you understand this and want to continue.\n""") subparser = subparsers.add_parser('help', parents=[common_parser], description='Extra help') - subparser.set_defaults(func=self.do_help) - subparser.add_argument('topic', metavar='TOPIC', type=str, + subparser.set_defaults( + func=functools.partial(self.do_help, parser, subparsers.choices)) + subparser.add_argument('topic', metavar='TOPIC', type=str, nargs='?', help='additional help on TOPIC') args = parser.parse_args(args or ['-h'])