cloudmonkey: autocomplete when cursor is not at the end, auto add space Signed-off-by: Rohit Yadav <[email protected]>
Project: http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/commit/3ce218da Tree: http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/tree/3ce218da Diff: http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/diff/3ce218da Branch: refs/heads/master Commit: 3ce218da7d8d9c93eec9930f56eb7b7c954c9b3b Parents: 3cd63b9 Author: Rohit Yadav <[email protected]> Authored: Wed Nov 12 23:42:08 2014 +0530 Committer: Rohit Yadav <[email protected]> Committed: Wed Nov 12 23:45:34 2014 +0530 ---------------------------------------------------------------------- cloudmonkey/cloudmonkey.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/blob/3ce218da/cloudmonkey/cloudmonkey.py ---------------------------------------------------------------------- diff --git a/cloudmonkey/cloudmonkey.py b/cloudmonkey/cloudmonkey.py index 187a7dc..607687b 100644 --- a/cloudmonkey/cloudmonkey.py +++ b/cloudmonkey/cloudmonkey.py @@ -409,7 +409,7 @@ class CloudMonkeyShell(cmd.Cmd, object): self.monkeyprint("Error on parsing and printing ", e) def completedefault(self, text, line, begidx, endidx): - partitions = line.partition(" ") + partitions = line[:endidx].partition(" ") verb = partitions[0].strip() rline = partitions[2].lstrip().partition(" ") subject = rline[0] @@ -423,7 +423,8 @@ class CloudMonkeyShell(cmd.Cmd, object): search_string = "" if separator != " ": # Complete verb subjects - autocompletions = self.apicache[verb].keys() + autocompletions = map(lambda x: x + " ", + self.apicache[verb].keys()) search_string = subject else: # Complete subject params autocompletions = map(lambda x: x + "=", @@ -431,7 +432,7 @@ class CloudMonkeyShell(cmd.Cmd, object): self.apicache[verb][subject]['params'])) search_string = text if self.paramcompletion == 'true': - param = line.split(" ")[-1] + param = line[:endidx].split(" ")[-1] idx = param.find("=") value = param[idx + 1:] param = param[:idx] @@ -484,7 +485,7 @@ class CloudMonkeyShell(cmd.Cmd, object): arg = filter(lambda x: x['name'] == param, params)[0] if "type" in arg and arg["type"] == "boolean": return filter(lambda x: x.startswith(value), - ["true", "false"]) + ["true ", "false "]) related = arg['related'] apis = filter(lambda x: 'list' in x, related) logger.debug("[Paramcompl] Related APIs: %s" % apis) @@ -515,7 +516,7 @@ class CloudMonkeyShell(cmd.Cmd, object): name = option[1] if uuid.startswith(value): print uuid, name - autocompletions = uuids + autocompletions = map(lambda x: x + " ", uuids) search_string = value if subject != "" and line.split(" ")[-1].find('=') == -1:
