From b7032382a7532d9a51c3ee55ff1c0216a6fb6229 Mon Sep 17 00:00:00 2001 From: Roman Vasilets Date: Thu, 27 Nov 2014 17:50:35 +0200 Subject: [PATCH] rally info: smart substitutions in the non-ambiguous case MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the user inputs his query just with a couple of typos, however, there is typically only one substitution suggested by the system: $ rally info find NovaServers.boot_and_delete_servers Failed to find any docs for query: 'NovaServers.boot_and_delete_servers' Did you mean one of these? NovaServers.boot_and_delete_server The idea is that in this case, when there is only one possible substitution, we could perform this substitution automatically, whithout requesting the user to do so. In the example above, Rally could response exactly as if the user typed the correct query (which is NovaServers.boot_and_delete_server, without ā€œsā€ at the end): $ rally info find NovaServers.boot_and_delete_servers NovaServers.boot_and_delete_server (benchmark scenario). Tests booting and then deleting an image. Change-Id: Ie2f8ff52e21c038ce72a77299de063d7ffddf24b --- rally/cmd/commands/info.py | 13 ++++++++----- tests/functional/test_cli_info.py | 15 +++++---------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/rally/cmd/commands/info.py b/rally/cmd/commands/info.py index b78d823ae0..31f3400e1f 100644 --- a/rally/cmd/commands/info.py +++ b/rally/cmd/commands/info.py @@ -87,11 +87,14 @@ class InfoCommands(object): print(info) else: substitutions = self._find_substitution(query) - print("Failed to find any docs for query: '%s'" % query) - if substitutions: - print("Did you mean one of these?\n\t%s" % - "\n\t".join(substitutions)) - return 1 + if len(substitutions) == 1: + print(self._find_info(substitutions[0])) + else: + print("Failed to find any docs for query: '%s'" % query) + if substitutions: + print("Did you mean one of these?\n\t%s" % + "\n\t".join(substitutions)) + return 1 def list(self): """List main entities in Rally for which rally info find works. diff --git a/tests/functional/test_cli_info.py b/tests/functional/test_cli_info.py index f006b0f03f..5c75dcfae9 100644 --- a/tests/functional/test_cli_info.py +++ b/tests/functional/test_cli_info.py @@ -54,18 +54,13 @@ class InfoTestCase(unittest.TestCase): ("info find NonExistingStuff")) def test_find_misspelling_typos(self): - marker_string = "ExistingServers" - try: - self.rally("info find ExistinfServert") - except utils.RallyCmdError as e: - self.assertIn(marker_string, e.output) + marker_string = "ExistingServers (server provider)." + self.assertIn(marker_string, self.rally("info find ExistinfServert")) def test_find_misspelling_truncated(self): - marker_string = "boot_and_delete_server" - try: - self.rally("info find boot_and_delete") - except utils.RallyCmdError as e: - self.assertIn(marker_string, e.output) + marker_string = ("NovaServers.boot_and_delete_server " + "(benchmark scenario).") + self.assertIn(marker_string, self.rally("info find boot_and_delete")) def test_list(self): output = self.rally("info list")