diff --git a/neutronclient/shell.py b/neutronclient/shell.py index 6cbe7a342..dc15c71b7 100644 --- a/neutronclient/shell.py +++ b/neutronclient/shell.py @@ -818,6 +818,10 @@ class NeutronShell(app.App): ) cmd_parser = cmd.get_parser(full_name) return run_command(cmd, cmd_parser, sub_argv) + except SystemExit: + print(_("Try 'neutron help %s' for more information.") % + cmd_name, file=sys.stderr) + raise except Exception as e: if self.options.verbose_level >= self.DEBUG_LEVEL: self.log.exception("%s", e) diff --git a/neutronclient/tests/unit/test_shell.py b/neutronclient/tests/unit/test_shell.py index 0fee6515d..284ca837e 100644 --- a/neutronclient/tests/unit/test_shell.py +++ b/neutronclient/tests/unit/test_shell.py @@ -59,7 +59,9 @@ class ShellTest(testtools.TestCase): fixtures.EnvironmentVariable( var, self.FAKE_ENV[var])) - def shell(self, argstr, check=False): + def shell(self, argstr, check=False, expected_val=0): + # expected_val is the expected return value after executing + # the command in NeutronShell orig = (sys.stdout, sys.stderr) clean_env = {} _old_env, os.environ = os.environ, clean_env.copy() @@ -70,7 +72,7 @@ class ShellTest(testtools.TestCase): _shell.run(argstr.split()) except SystemExit: exc_type, exc_value, exc_traceback = sys.exc_info() - self.assertEqual(0, exc_value.code) + self.assertEqual(expected_val, exc_value.code) finally: stdout = sys.stdout.getvalue() stderr = sys.stderr.getvalue() @@ -211,3 +213,15 @@ class ShellTest(testtools.TestCase): namespace = parser.parse_args([]) self.assertEqual(50, namespace.http_timeout) + + def test_run_incomplete_command(self): + self.useFixture(fixtures.FakeLogger(level=logging.DEBUG)) + cmd = ( + '--os-username test --os-password test --os-project-id test ' + '--os-auth-strategy keystone --os-auth-url ' + '%s port-create' % + DEFAULT_AUTH_URL) + stdout, stderr = self.shell(cmd, check=True, expected_val=2) + search_str = "Try 'neutron help port-create' for more information" + self.assertTrue(any(search_str in string for string + in stderr.split('\n')))