Michael Pasternak has uploaded a new change for review. Change subject: cli: List/Show suggests parent+child as single param #950398 ......................................................................
cli: List/Show suggests parent+child as single param #950398 Change-Id: Ice679b53fdbb2495721b224784f019405244e861 Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=950398 Signed-off-by: Michael Pasternak <[email protected]> --- M src/ovirtcli/shell/engineshell.py M src/ovirtcli/utils/methodhelper.py 2 files changed, 42 insertions(+), 14 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine-cli refs/changes/35/14135/1 diff --git a/src/ovirtcli/shell/engineshell.py b/src/ovirtcli/shell/engineshell.py index 36b8b8c..4425537 100644 --- a/src/ovirtcli/shell/engineshell.py +++ b/src/ovirtcli/shell/engineshell.py @@ -33,16 +33,17 @@ from ovirtcli.shell.consolecmdshell import ConsoleCmdShell from ovirtcli.shell.pingcmdshell import PingCmdShell from ovirtcli.shell.statuscmdshell import StatusCmdShell -from ovirtcli.settings import OvirtCliSettings from ovirtcli.shell.clearcmdshell import ClearCmdShell - -from cli.command.help import HelpCommand -from ovirtcli.prompt import PromptMode +from ovirtcli.shell.summarycmdshell import SummaryCmdShell from ovirtcli.shell.filecmdshell import FileCmdShell from ovirtcli.shell.historycmdshell import HistoryCmdShell -from cli.messages import Messages from ovirtcli.shell.infocmdshell import InfoCmdShell -from ovirtcli.shell.summarycmdshell import SummaryCmdShell + +from ovirtcli.settings import OvirtCliSettings +from ovirtcli.prompt import PromptMode + +from cli.command.help import HelpCommand +from cli.messages import Messages class EngineShell(cmd.Cmd, ConnectCmdShell, ActionCmdShell, \ ShowCmdShell, ListCmdShell, UpdateCmdShell, \ @@ -168,7 +169,7 @@ def normalize(self, line): normalized = line.lstrip() - rg = re.compile('((?:[a-z][a-z]+))( )(-)(-)(help)',re.IGNORECASE|re.DOTALL) + rg = re.compile('((?:[a-z][a-z]+))( )(-)(-)(help)', re.IGNORECASE | re.DOTALL) m = rg.search(normalized) if m: normalized = 'help ' + m.group(1) @@ -178,6 +179,13 @@ ret = cmd.Cmd.parseline(self, line) return ret + def completenames(self, text, *ignored): + dotext = 'do_' + text + res = [a[3:] for a in self.get_names() if a.startswith(dotext)] + if res and len(res) == 1: + res[0] = res[0] + ' ' + return res + def complete(self, text, state): content = [] line = readline.get_line_buffer().lstrip() diff --git a/src/ovirtcli/utils/methodhelper.py b/src/ovirtcli/utils/methodhelper.py index 8ad9bc4..293e677 100644 --- a/src/ovirtcli/utils/methodhelper.py +++ b/src/ovirtcli/utils/methodhelper.py @@ -57,8 +57,11 @@ if not groupOptions: if args: if len(args) == 3: - cand = expender(args[1], module, method) if expendNestedTypes\ - else args[1] + if expendNestedTypes: + cand = expender(args[1], module, method, []) + else: + cand = args[1] + cand = ", ".join(cand) if type(cand) == list else cand if not holder.has_key(args[2]): @@ -82,8 +85,10 @@ else: if args: if len(args) == 3: - cand = expender(args[1], module, method) if expendNestedTypes\ - else args[1] + if expendNestedTypes: + cand = expender(args[1], module, method, []) + else: + cand = args[1] cand = cand if type(cand) == list else [cand] if not holder.has_key(args[2]): @@ -115,12 +120,27 @@ holder[k] = ", ".join(sorted(new_val)) @staticmethod - def __expend_nested_type(type_name, module, method): + def __expend_nested_type(type_name, module, method, expended_types): + """Recursive method's args types resolution""" + getMethodArgs = MethodHelper.getMethodArgs + expend_nested_type = MethodHelper.__expend_nested_type + from ovirtcli.utils.typehelper import TypeHelper typ = TypeHelper.getDecoratorType(type_name) + if typ: - return MethodHelper.getMethodArgs(module, typ, method, drop_self=True) - return type_name + expended_types_tmp = getMethodArgs(module, typ, method, drop_self=True) + if len(expended_types_tmp) > 1: + for item in expended_types_tmp: + expend_nested_type(item, module, method, expended_types) + elif len(expended_types_tmp) > 0: + expended_types.append(expended_types_tmp[0]) + else: + if expended_types and len(expended_types) > 0: + expended_types.append(type_name) + else: + expended_types = type_name + return expended_types @staticmethod def get_documented_arguments(method_ref, as_params_collection=False, spilt_or=False): -- To view, visit http://gerrit.ovirt.org/14135 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ice679b53fdbb2495721b224784f019405244e861 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine-cli Gerrit-Branch: master Gerrit-Owner: Michael Pasternak <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
