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.
This commit is contained in:
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,6 +85,9 @@ def execute(raw_args=sys.argv):
|
||||
autocomplete(parser)
|
||||
# Parse and run appropriate command
|
||||
args = parser.parse_args(remaining_args)
|
||||
if not args.command:
|
||||
parser.print_help()
|
||||
else:
|
||||
args.prog = "pubs" # FIXME?
|
||||
args.func(conf, args)
|
||||
|
||||
|
@ -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…
x
Reference in New Issue
Block a user