summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cliff/app.py9
-rw-r--r--cliff/tests/test_app.py13
2 files changed, 21 insertions, 1 deletions
diff --git a/cliff/app.py b/cliff/app.py
index 5cbd195..39ccbdd 100644
--- a/cliff/app.py
+++ b/cliff/app.py
@@ -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
diff --git a/cliff/tests/test_app.py b/cliff/tests/test_app.py
index 5f13007..e3bc12e 100644
--- a/cliff/tests/test_app.py
+++ b/cliff/tests/test_app.py
@@ -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)