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__':
# parse the arguments
opts = composer_cli_parser().parse_args()
arg_parser = composer_cli_parser()
opts = arg_parser.parse_args()
if opts.showver:
print(VERSION)
@ -59,6 +60,16 @@ if __name__ == '__main__':
setup_logging(opts.logfile)
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 = []
# Check to see if the socket exists and can be accessed

View File

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