If the help subcommand is given, print the help output.

This isn't a real subcommand like the others.  The option processing
just intercepts it and prints the output.  Given that we're subcommand
based, it makes sense to support this in addition to --help.

(cherry picked from commit 18620700fd)
This commit is contained in:
Chris Lumens 2018-06-28 10:07:33 -04:00 committed by Brian C. Lane
parent f05a95ebe5
commit eca6a01008
2 changed files with 16 additions and 8 deletions

View File

@ -47,7 +47,8 @@ def setup_logging(logfile):
if __name__ == '__main__': if __name__ == '__main__':
# parse the arguments # parse the arguments
opts = composer_cli_parser().parse_args() arg_parser = composer_cli_parser()
opts = arg_parser.parse_args()
if opts.showver: if opts.showver:
print(VERSION) print(VERSION)
@ -59,6 +60,16 @@ if __name__ == '__main__':
setup_logging(opts.logfile) setup_logging(opts.logfile)
log.debug("opts=%s", opts) log.debug("opts=%s", opts)
if len(opts.args) == 0:
log.error("Missing command")
sys.exit(1)
elif opts.args[0] == "help":
arg_parser.print_help()
sys.exit(0)
elif len(opts.args) == 1:
log.error("Missing %s sub-command", opts.args[0])
sys.exit(1)
errors = [] errors = []
# Check to see if the socket exists and can be accessed # Check to see if the socket exists and can be accessed

View File

@ -40,15 +40,12 @@ def main(opts):
:param opts: Cmdline arguments :param opts: Cmdline arguments
:type opts: argparse.Namespace :type opts: argparse.Namespace
""" """
if len(opts.args) == 0:
log.error("Missing command") # Making sure opts.args is not empty (thus, has a command and subcommand)
return 1 # is already handled in src/bin/composer-cli.
elif opts.args[0] not in command_map: if opts.args[0] not in command_map:
log.error("Unknown command %s", opts.args[0]) log.error("Unknown command %s", opts.args[0])
return 1 return 1
if len(opts.args) == 1:
log.error("Missing %s sub-command", opts.args[0])
return 1
else: else:
try: try:
return command_map[opts.args[0]](opts) return command_map[opts.args[0]](opts)