From ed9b3f98d24210d4f44bffeeaf4ed171d63f95e0 Mon Sep 17 00:00:00 2001 From: David Shrewsbury Date: Wed, 11 Jul 2018 12:56:09 -0400 Subject: [PATCH] Handle no arguments Running 'pbrx' with no arguments is a thing folks may do. We shouldn't throw exceptions at them in this case, but, instead, some help text. Change-Id: Ibed0da165f062125cf298e2d9b3dce54c4b93420 --- pbrx/cmd/main.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pbrx/cmd/main.py b/pbrx/cmd/main.py index 526e789..aa36593 100644 --- a/pbrx/cmd/main.py +++ b/pbrx/cmd/main.py @@ -82,7 +82,8 @@ def main(): ) subparsers = parser.add_subparsers( - title="commands", description="valid commands", help="additional help" + title="commands", description="valid commands", + dest="command", help="additional help" ) cmd_siblings = subparsers.add_parser( @@ -110,9 +111,13 @@ def main(): args = parser.parse_args() setup_logging(args.log_config, args.debug) + + if not args.command: + parser.print_help() + return 1 + try: return args.func(args) - except Exception as e: log.exception(str(e)) return 1