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:
		@@ -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='<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():
 | 
			
		||||
    """Main entry-point for cratonclient's CLI."""
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user