Skip to content

Commit f6e10c6

Browse files
committed
spire: implement "spire help [subcommand]"
Add a "help" subcommand to any subcommand which takes subcommands.
1 parent 979626e commit f6e10c6

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

platform/spire/src/command.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,26 @@ def configure(self, command: list, parser: argparse.ArgumentParser):
5353
except AttributeError as e:
5454
raise Exception("error configuring subcommand {!r}".format(subcommand)) from e
5555

56+
if 'help' not in self.mapping:
57+
help_subparser = subparsers.add_parser(
58+
'help',
59+
description='print help about this command or a subcommnad',
60+
help='show this help message and exit')
61+
help_subparser.add_argument('subcommand', nargs='?')
62+
def help_function(aargs):
63+
if aargs.subcommand is None:
64+
parser.print_help()
65+
else:
66+
try:
67+
subparser = subparsers.choices[aargs.subcommand]
68+
except KeyError:
69+
print('{}: no such subcommand'.format(aargs.subcommand))
70+
parser.print_help()
71+
return
72+
subparser.print_help()
73+
help_subparser.set_defaults(argparse_invoke=help_function,
74+
argparse_parser=help_subparser)
75+
5676
def short_doc(self):
5777
return self.__doc__
5878

0 commit comments

Comments
 (0)