Michael Pasternak has uploaded a new change for review. Change subject: cli: history command does not support pipe redirection #854486 ......................................................................
cli: history command does not support pipe redirection #854486 https://bugzilla.redhat.com/show_bug.cgi?id=854486 Change-Id: I23cd1f15727cfc586ce5dc66146e7b788f4284fb Signed-off-by: Michael Pasternak <mpast...@redhat.com> --- M src/cli/parser.py M src/ovirtcli/command/__init__.py A src/ovirtcli/command/history.py M src/ovirtcli/context.py M src/ovirtcli/shell/engineshell.py M src/ovirtcli/shell/historycmdshell.py 6 files changed, 77 insertions(+), 43 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine-cli refs/changes/02/7902/1 diff --git a/src/cli/parser.py b/src/cli/parser.py index e3ebb38..0b7eb69 100644 --- a/src/cli/parser.py +++ b/src/cli/parser.py @@ -169,6 +169,7 @@ """argument : UUID | WORD | STRING + | NUMBER """ p[0] = p[1] diff --git a/src/ovirtcli/command/__init__.py b/src/ovirtcli/command/__init__.py index 3a221d4..94c02bb 100644 --- a/src/ovirtcli/command/__init__.py +++ b/src/ovirtcli/command/__init__.py @@ -12,3 +12,4 @@ from ovirtcli.command.show import ShowCommand from ovirtcli.command.status import StatusCommand from ovirtcli.command.update import UpdateCommand +from ovirtcli.command.history import HistoryCommand diff --git a/src/ovirtcli/command/history.py b/src/ovirtcli/command/history.py new file mode 100644 index 0000000..43280f7 --- /dev/null +++ b/src/ovirtcli/command/history.py @@ -0,0 +1,70 @@ +# +# Copyright (c) 2010 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +from ovirtcli.command.command import OvirtCommand + + +class HistoryCommand(OvirtCommand): + + name = 'history' + description = 'displaying commands history' + args_check = (0, 1) + valid_options = [ ('*', int) ] + helptext = """\ + == Usage == + + history [indx] + + or + + recursive search by ctrl+r + + == Description == + + Displaying commands history + + == Examples == + + - ctrl+r + + - history + + - history 1 + + """ + + def execute(self): + args = self.arguments + context = self.context + hformat = '[%d] %s' + + if len(args) > 0: + indx = args[0] + try: + slide = int(indx) + h_item = context.history.get(slide) + if h_item: + self.write(hformat % (slide , str(h_item))) + except Exception, e: + self.error(str(e)) + else: + i = 0 + history = context.history.list() + if history: + for item in history: + self.write(hformat % (i , str(item))) + i += 1 + self.write('') diff --git a/src/ovirtcli/context.py b/src/ovirtcli/context.py index 05b6166..b0446fe 100644 --- a/src/ovirtcli/context.py +++ b/src/ovirtcli/context.py @@ -25,6 +25,7 @@ from ovirtcli.object import create import pkg_resources from ovirtcli.command.info import InfoCommand +from ovirtcli.historymanager import HistoryManager class OvirtCliExecutionContext(ExecutionContext): @@ -48,6 +49,7 @@ self.settings.add_callback('ovirt-shell:output_format', self._set_formatter) self.product_info = None self.sdk_version, self.cli_version, self.backend_version = self.__get_version_info() + self.history = HistoryManager() def __get_version_info(self): SNAPSHOT_SUFFIX = '-SNAPSHOT' @@ -101,6 +103,7 @@ self.add_command(StatusCommand) self.add_command(UpdateCommand) self.add_command(InfoCommand) + self.add_command(HistoryCommand) def _get_prompt_variables(self): """Return a dict with prompt variables.""" diff --git a/src/ovirtcli/shell/engineshell.py b/src/ovirtcli/shell/engineshell.py index 4a1ef4b..7e2584b 100644 --- a/src/ovirtcli/shell/engineshell.py +++ b/src/ovirtcli/shell/engineshell.py @@ -38,7 +38,6 @@ from cli.command.help import HelpCommand from ovirtcli.prompt import PromptMode from ovirtcli.shell.filecmdshell import FileCmdShell -from ovirtcli.historymanager import HistoryManager from ovirtcli.shell.historycmdshell import HistoryCmdShell from cli.messages import Messages from ovirtcli.shell.infocmdshell import InfoCmdShell @@ -81,7 +80,6 @@ readline.set_completer_delims(' ') signal.signal(signal.SIGINT, self.handler) - self.history = HistoryManager() ########################### SYSTEM ################################# def cmdloop(self, intro=None, clear=True): try: diff --git a/src/ovirtcli/shell/historycmdshell.py b/src/ovirtcli/shell/historycmdshell.py index efffde4..e34da3c 100644 --- a/src/ovirtcli/shell/historycmdshell.py +++ b/src/ovirtcli/shell/historycmdshell.py @@ -24,44 +24,5 @@ def __init__(self, context, parser): CmdShell.__init__(self, context, parser) - def do_history(self, indx): - """\ - == Usage == - - history [indx] - - or - - recursive search by ctrl+r - - == Description == - - List/Retrieves executed command/s - - == Examples == - - - ctrl+r - - - history - - - history 1 - - """ - hformat = '[%d] %s' - - if indx: - try: - slide = int(indx) - h_item = self.owner.history.get(slide) - if h_item: - self.owner._print(hformat % (slide , str(h_item))) - except Exception, e: - self.owner._error(str(e)) - else: - i = 0 - history = self.history.list() - if history: - for item in history: - print hformat % (i , str(item)) - i += 1 - print '' + def do_history(self, args): + return self.context.execute_string(HistoryCmdShell.NAME + ' ' + args + '\n') -- To view, visit http://gerrit.ovirt.org/7902 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I23cd1f15727cfc586ce5dc66146e7b788f4284fb Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine-cli Gerrit-Branch: master Gerrit-Owner: Michael Pasternak <mpast...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches