diff options
| author | Jenkins <jenkins@review.openstack.org> | 2015-01-13 16:26:56 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2015-01-13 16:26:56 +0000 |
| commit | 877df07dee5997fa14386fa21e304c26c76233ea (patch) | |
| tree | 82a543aae5ea4c567bed9921cbcc1eb9f60ed55e | |
| parent | adf358d2b05f2b21cece702fedd58aed0c33b705 (diff) | |
| parent | 187c36c19b0e43740df3c46c6f34d3d0ad76a510 (diff) | |
| download | python-neutronclient-877df07dee5997fa14386fa21e304c26c76233ea.tar.gz | |
Merge "Correct the bash completion of CLI"
| -rw-r--r-- | neutronclient/shell.py | 11 | ||||
| -rw-r--r-- | neutronclient/tests/unit/test_shell.py | 23 |
2 files changed, 33 insertions, 1 deletions
diff --git a/neutronclient/shell.py b/neutronclient/shell.py index 0329d52..ad73b50 100644 --- a/neutronclient/shell.py +++ b/neutronclient/shell.py @@ -38,6 +38,7 @@ from cliff import app from cliff import commandmanager from neutronclient.common import clientmanager +from neutronclient.common import command as openstack_command from neutronclient.common import exceptions as exc from neutronclient.common import utils from neutronclient.i18n import _ @@ -116,7 +117,12 @@ def check_non_negative_int(value): return value +class BashCompletionCommand(openstack_command.OpenStackCommand): + """Prints all of the commands and options for bash-completion.""" + resource = "bash_completion" + COMMAND_V2 = { + 'bash-completion': BashCompletionCommand, 'net-list': network.ListNetwork, 'net-external-list': network.ListExternalNetwork, 'net-show': network.ShowNetwork, @@ -345,6 +351,9 @@ class NeutronShell(app.App): for k, v in self.commands[apiversion].items(): self.command_manager.add_command(k, v) + # Pop the 'complete' to correct the outputs of 'neutron help'. + self.command_manager.commands.pop('complete') + # This is instantiated in initialize_app() only when using # password flow auth self.auth_client = None @@ -644,7 +653,7 @@ class NeutronShell(app.App): help_pos = -1 help_command_pos = -1 for arg in argv: - if arg == 'bash-completion': + if arg == 'bash-completion' and help_command_pos == -1: self._bash_completion() return 0 if arg in self.commands[self.api_version]: diff --git a/neutronclient/tests/unit/test_shell.py b/neutronclient/tests/unit/test_shell.py index 404682d..091c9ec 100644 --- a/neutronclient/tests/unit/test_shell.py +++ b/neutronclient/tests/unit/test_shell.py @@ -127,6 +127,29 @@ class ShellTest(testtools.TestCase): matchers.MatchesRegex(required)) self.assertFalse(stderr) + def test_bash_completion_in_outputs_of_help_command(self): + help_text, stderr = self.shell('help') + self.assertFalse(stderr) + completion_cmd = "bash-completion" + completion_help_str = ("Prints all of the commands and options " + "for bash-completion.") + self.assertIn(completion_cmd, help_text) + self.assertIn(completion_help_str, help_text) + + def test_bash_completion_command(self): + # just check we have some output + required = [ + '.*--tenant_id', + '.*--client-certificate', + '.*help', + '.*gateway-device-create', + '.*--dns-nameserver'] + help_text, stderr = self.shell('neutron bash-completion') + self.assertFalse(stderr) + for r in required: + self.assertThat(help_text, + matchers.MatchesRegex(r, re.DOTALL | re.MULTILINE)) + def test_unknown_auth_strategy(self): self.useFixture(fixtures.FakeLogger(level=logging.DEBUG)) stdout, stderr = self.shell('--os-auth-strategy fake quota-list') |
