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)
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):

@ -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):

Loading…
Cancel
Save