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)
|
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,8 +85,11 @@ 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)
|
||||||
args.prog = "pubs" # FIXME?
|
if not args.command:
|
||||||
args.func(conf, args)
|
parser.print_help()
|
||||||
|
else:
|
||||||
|
args.prog = "pubs" # FIXME?
|
||||||
|
args.func(conf, args)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if not uis.get_ui().handle_exception(e):
|
if not uis.get_ui().handle_exception(e):
|
||||||
|
@ -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…
x
Reference in New Issue
Block a user