Merge pull request #57 from kljohann/help

accept names of other commands in help command
This commit is contained in:
Jonas Borgström 2014-03-22 20:29:13 +01:00
commit 8e43ebcd29
1 changed files with 11 additions and 7 deletions

View File

@ -2,6 +2,7 @@ import argparse
from binascii import hexlify from binascii import hexlify
from datetime import datetime from datetime import datetime
from operator import attrgetter from operator import attrgetter
import functools
import io import io
import os import os
import stat 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 $ attic create -e /home/user/cache/ repo.attic / /home/user/cache/important
''' '''
def do_help(self, args): def do_help(self, parser, commands, args):
if args.topic in self.helptext: if not args.topic:
parser.print_help()
elif args.topic in self.helptext:
print(self.helptext[args.topic]) print(self.helptext[args.topic])
elif args.topic in commands:
commands[args.topic].print_help()
else: else:
# FIXME: If topic is one of the regular commands, show that help. parser.error('No help available on %s' % (args.topic,))
# Otherwise, show the default global help.
print('No help available on %s' % (args.topic,))
return self.exit_code return self.exit_code
def preprocess_args(self, args): 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], subparser = subparsers.add_parser('help', parents=[common_parser],
description='Extra help') description='Extra help')
subparser.set_defaults(func=self.do_help) subparser.set_defaults(
subparser.add_argument('topic', metavar='TOPIC', type=str, func=functools.partial(self.do_help, parser, subparsers.choices))
subparser.add_argument('topic', metavar='TOPIC', type=str, nargs='?',
help='additional help on TOPIC') help='additional help on TOPIC')
args = parser.parse_args(args or ['-h']) args = parser.parse_args(args or ['-h'])