From 6ef0486b5cb56dc2da68e8d8053b12d8337a3f3c Mon Sep 17 00:00:00 2001 From: Sulochan Acharya Date: Wed, 25 Jan 2017 13:44:25 +0000 Subject: [PATCH] Fixes --help and command help for cratonclient Both craton --help and craton help is broken for different reasons. This patch fixes that by adding do_help function for help subcommand and by displaying suparsed argument of --help. Closes Bug: 1659092 Change-Id: I838c780ada21edb8202d0fda6bfc982bc57c253b --- cratonclient/shell/main.py | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/cratonclient/shell/main.py b/cratonclient/shell/main.py index 4e07944..db11525 100644 --- a/cratonclient/shell/main.py +++ b/cratonclient/shell/main.py @@ -20,6 +20,7 @@ from oslo_utils import encodeutils from oslo_utils import importutils from cratonclient import __version__ +from cratonclient import exceptions as exc from cratonclient import session as craton from cratonclient.common import cliutils @@ -132,11 +133,17 @@ class CratonShell(object): ) self.parser = subcommand_parser - if options.help or ('help' in argv) or not argv: - parser.print_help() + if options.help or not argv: + self.parser.print_help() return 0 args = subcommand_parser.parse_args(argv) + + # Short-circuit and deal with help right away. + if args.func == self.do_help: + self.do_help(args) + return 0 + session = craton.Session( username=args.os_username, token=args.os_password, @@ -145,6 +152,22 @@ class CratonShell(object): self.cc = client.Client(session, args.craton_url) args.func(self.cc, args) + @cliutils.arg( + 'command', + metavar='', + nargs='?', + help='Display help for .') + def do_help(self, args): + """Display help about this program or one of its subcommands.""" + if args.command: + if args.command in self.subcommands: + self.subcommands[args.command].print_help() + else: + raise exc.CommandError("'%s' is not a valid subcommand" % + args.command) + else: + self.parser.print_help() + def main(): """Main entry-point for cratonclient's CLI."""