From ac3a8d8bf23c0a7900befe47db0a632c911ac7c5 Mon Sep 17 00:00:00 2001 From: Bill Flynn Date: Tue, 28 Nov 2017 17:32:13 -0500 Subject: [PATCH] Print help menu when no subcommands applied Made subparsers not required in the main parser, but if no commands are parsed, then the parser prints its help. When a command is present, the normal functionality preserved. Removed the single unittest that checks for this exact behavior. --- pubs/pubs_cmd.py | 9 ++++++--- tests/test_usecase.py | 7 ------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/pubs/pubs_cmd.py b/pubs/pubs_cmd.py index da8a43e..e849f69 100644 --- a/pubs/pubs_cmd.py +++ b/pubs/pubs_cmd.py @@ -69,7 +69,7 @@ def execute(raw_args=sys.argv): prog="pubs", add_help=True) parser.add_argument('--version', action='version', version=__version__) subparsers = parser.add_subparsers(title="valid commands", dest="command") - subparsers.required = True + #subparsers.required = True # Populate the parser with core commands for cmd_name, cmd_mod in CORE_CMDS.items(): @@ -85,8 +85,11 @@ def execute(raw_args=sys.argv): autocomplete(parser) # Parse and run appropriate command args = parser.parse_args(remaining_args) - args.prog = "pubs" # FIXME? - args.func(conf, args) + if not args.command: + parser.print_help() + else: + args.prog = "pubs" # FIXME? + args.func(conf, args) except Exception as e: if not uis.get_ui().handle_exception(e): diff --git a/tests/test_usecase.py b/tests/test_usecase.py index 506ed03..ce870cf 100644 --- a/tests/test_usecase.py +++ b/tests/test_usecase.py @@ -187,13 +187,6 @@ class URLContentTestCase(DataCommandTestCase): # Actual tests -class TestAlone(CommandTestCase): - - def test_alone_misses_command(self): - with self.assertRaises(FakeSystemExit): - self.execute_cmds(['pubs']) - - class TestInit(CommandTestCase): def test_init(self):