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.
main
Bill Flynn 7 years ago
parent 5676cb49a9
commit ac3a8d8bf2

@ -69,7 +69,7 @@ def execute(raw_args=sys.argv):
prog="pubs", add_help=True) prog="pubs", add_help=True)
parser.add_argument('--version', action='version', version=__version__) parser.add_argument('--version', action='version', version=__version__)
subparsers = parser.add_subparsers(title="valid commands", dest="command") subparsers = parser.add_subparsers(title="valid commands", dest="command")
subparsers.required = True #subparsers.required = True
# Populate the parser with core commands # Populate the parser with core commands
for cmd_name, cmd_mod in CORE_CMDS.items(): for cmd_name, cmd_mod in CORE_CMDS.items():
@ -85,6 +85,9 @@ def execute(raw_args=sys.argv):
autocomplete(parser) autocomplete(parser)
# Parse and run appropriate command # Parse and run appropriate command
args = parser.parse_args(remaining_args) args = parser.parse_args(remaining_args)
if not args.command:
parser.print_help()
else:
args.prog = "pubs" # FIXME? args.prog = "pubs" # FIXME?
args.func(conf, args) args.func(conf, args)

@ -187,13 +187,6 @@ class URLContentTestCase(DataCommandTestCase):
# Actual tests # Actual tests
class TestAlone(CommandTestCase):
def test_alone_misses_command(self):
with self.assertRaises(FakeSystemExit):
self.execute_cmds(['pubs'])
class TestInit(CommandTestCase): class TestInit(CommandTestCase):
def test_init(self): def test_init(self):

Loading…
Cancel
Save