Merge pull request #43 from kryskool/kryskool/unknow-cmd-better
Display better error message on unknown command, and return code 1
This commit is contained in:
@@ -257,7 +257,14 @@ class App(object):
|
||||
return 0
|
||||
|
||||
def run_subcommand(self, argv):
|
||||
subcommand = self.command_manager.find_command(argv)
|
||||
try:
|
||||
subcommand = self.command_manager.find_command(argv)
|
||||
except ValueError as err:
|
||||
if self.options.debug:
|
||||
raise
|
||||
else:
|
||||
LOG.error(err)
|
||||
return 2
|
||||
cmd_factory, cmd_name, sub_argv = subcommand
|
||||
cmd = cmd_factory(self, self.options)
|
||||
err = None
|
||||
|
||||
@@ -374,3 +374,16 @@ def test_error_encoding_sys():
|
||||
app.stderr.write(u_data)
|
||||
actual = stderr.getvalue()
|
||||
assert data == actual
|
||||
|
||||
|
||||
def test_unknown_cmd():
|
||||
app, command = make_app()
|
||||
assert app.run(['hell']) == 2
|
||||
|
||||
|
||||
def test_unknown_cmd_debug():
|
||||
app, command = make_app()
|
||||
try:
|
||||
app.run(['--debug', 'hell']) == 2
|
||||
except ValueError as err:
|
||||
assert "['hell']" in ('%s' % err)
|
||||
|
||||
Reference in New Issue
Block a user