Fixes --help and command help for cratonclient
Both craton --help and craton help <COMMAND> 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
This commit is contained in:
parent
4c1fac38bf
commit
6ef0486b5c
@ -20,6 +20,7 @@ from oslo_utils import encodeutils
|
|||||||
from oslo_utils import importutils
|
from oslo_utils import importutils
|
||||||
|
|
||||||
from cratonclient import __version__
|
from cratonclient import __version__
|
||||||
|
from cratonclient import exceptions as exc
|
||||||
from cratonclient import session as craton
|
from cratonclient import session as craton
|
||||||
|
|
||||||
from cratonclient.common import cliutils
|
from cratonclient.common import cliutils
|
||||||
@ -132,11 +133,17 @@ class CratonShell(object):
|
|||||||
)
|
)
|
||||||
self.parser = subcommand_parser
|
self.parser = subcommand_parser
|
||||||
|
|
||||||
if options.help or ('help' in argv) or not argv:
|
if options.help or not argv:
|
||||||
parser.print_help()
|
self.parser.print_help()
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
args = subcommand_parser.parse_args(argv)
|
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(
|
session = craton.Session(
|
||||||
username=args.os_username,
|
username=args.os_username,
|
||||||
token=args.os_password,
|
token=args.os_password,
|
||||||
@ -145,6 +152,22 @@ class CratonShell(object):
|
|||||||
self.cc = client.Client(session, args.craton_url)
|
self.cc = client.Client(session, args.craton_url)
|
||||||
args.func(self.cc, args)
|
args.func(self.cc, args)
|
||||||
|
|
||||||
|
@cliutils.arg(
|
||||||
|
'command',
|
||||||
|
metavar='<subcommand>',
|
||||||
|
nargs='?',
|
||||||
|
help='Display help for <subcommand>.')
|
||||||
|
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():
|
def main():
|
||||||
"""Main entry-point for cratonclient's CLI."""
|
"""Main entry-point for cratonclient's CLI."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user