Juan Hernandez has uploaded a new change for review.

Change subject: cli: Remove completely the -p and --password options
......................................................................

cli: Remove completely the -p and --password options

These options have already been hidden to the user in previous changes.
This patch removes them completely, and also the overriden methods in
the options parser that were required to support them.

Change-Id: Ic08f2849ef6209819c4b72c26606ec5be1f8248c
Signed-off-by: Juan Hernandez <juan.hernan...@redhat.com>
---
M src/cli/context.py
M src/ovirtcli/infrastructure/context.py
M src/ovirtcli/infrastructure/options.py
M src/ovirtcli/main.py
4 files changed, 5 insertions(+), 97 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine-cli refs/changes/56/36256/1

diff --git a/src/cli/context.py b/src/cli/context.py
index f537607..35472e8 100644
--- a/src/cli/context.py
+++ b/src/cli/context.py
@@ -57,12 +57,11 @@
     welcome = None
     goodbye = None
 
-    def __init__(self, cmdin=None, args=None, option_parser=None):
+    def __init__(self, cmdin=None, args=None):
         """Constructor."""
         self.parameters_cash = {}
         self.cmdin = cmdin or sys.stdin
         self.args = args
-        self.option_parser = option_parser
         self.commands = []
         self.status = None
         self.mode = ExecutionMode.SHELL
@@ -109,11 +108,6 @@
         finally:
             sys.stdin.flush()
 
-    def __exclude_app_options(self):
-        for opt in self.option_parser.app_options:
-            if self.__is_option_specified_in_cli_args(opt):
-                self.__option_error(opt)
-
     def __option_error(self, opt):
         from cli.messages import Messages
         sys.exit('\n' + Messages.Error.NO_SUCH_OPTION % opt + '\n')
@@ -138,7 +132,6 @@
             self.settings.write_example_config_file()
         elif old_format:
             self.settings.write_config_file()
-        self.__exclude_app_options()
         self.settings.add_callback('cli:debug', self._set_debug)
         self._set_debug('cli:debug', self.settings['cli:debug'])
 
diff --git a/src/ovirtcli/infrastructure/context.py 
b/src/ovirtcli/infrastructure/context.py
index 3596e11..1221c26 100644
--- a/src/ovirtcli/infrastructure/context.py
+++ b/src/ovirtcli/infrastructure/context.py
@@ -43,8 +43,8 @@
     CLI_MODULE_NAME = "ovirt-shell"
     DEFAULT_VERSION = (0, 0, 0, 0)
 
-    def __init__(self, args=None, option_parser=None):
-        super(OvirtCliExecutionContext, self).__init__(args=args, 
option_parser=option_parser)
+    def __init__(self, args=None):
+        super(OvirtCliExecutionContext, self).__init__(args=args)
         self.connection = None
         self.url = None
         self.formatter = create(Formatter, 
self.settings['ovirt-shell:output_format'])
diff --git a/src/ovirtcli/infrastructure/options.py 
b/src/ovirtcli/infrastructure/options.py
index a8dd143..94d35b1 100644
--- a/src/ovirtcli/infrastructure/options.py
+++ b/src/ovirtcli/infrastructure/options.py
@@ -15,9 +15,8 @@
 #
 
 
-import sys
 import textwrap
-from optparse import OptionParser, BadOptionError, AmbiguousOptionError
+from optparse import OptionParser
 from ovirtcli.infrastructure import settings
 
 
@@ -63,88 +62,4 @@
                         help='use Kerberos authentication')
         self.disable_interspersed_args()
 
-        # list of hidden app. options (long format)
-        self.app_options = ['--password', '-p']
 
-    def exit(self, status=0, msg=None):
-        self.values._exit = True
-        if msg: print (msg + 'see help for more details.\n')
-        sys.exit(status)
-
-    def _match_long_opt(self, opt):
-        """_match_long_opt(opt : string) -> string
-
-        Determine which long option string 'opt' matches, ie. which one
-        it is an unambiguous abbrevation for.  Raises BadOptionError if
-        'opt' doesn't unambiguously match any long option string.
-        """
-        return self._match_abbrev(opt, self._long_opt)
-
-    def _match_abbrev(self, s, wordmap):
-        """_match_abbrev(s : string, wordmap : {string : Option}) -> string
-
-        Return the string key in 'wordmap' for which 's' is an unambiguous
-        abbreviation.  If 's' is found to be ambiguous or doesn't match any of
-        'words', raise BadOptionError.
-        """
-
-        # Is there an exact match?
-        if s in wordmap:
-            return s
-        else:
-            # Isolate all words with s as a prefix.
-            option_keys = wordmap.keys()
-            for item in self.app_options:
-                if item not in  option_keys:
-                    option_keys.append(item)
-            possibilities = [word for word in option_keys
-                             if word.startswith(s)]
-            # No exact match, so there had better be just one possibility.
-            if len(possibilities) == 1:
-                return possibilities[0]
-            elif not possibilities:
-                raise BadOptionError(s)
-            else:
-                # More than one possible completion: ambiguous prefix.
-                possibilities.sort()
-                raise AmbiguousOptionError(s, possibilities)
-
-    def _process_long_opt(self, rargs, values):
-        arg = rargs.pop(0)
-
-        # Value explicitly attached to arg?  Pretend it's the next
-        # argument.
-        if "=" in arg:
-            (opt, next_arg) = arg.split("=", 1)
-            rargs.insert(0, next_arg)
-            had_explicit_value = True
-        else:
-            opt = arg
-            had_explicit_value = False
-
-        opt = self._match_long_opt(opt)
-        if opt not in self._long_opt.keys() and opt in self.app_options:
-            # This is app. option (long format)
-            self.add_option('', opt, help='private app. option')
-        option = self._long_opt[opt]
-        if option.takes_value():
-            nargs = option.nargs
-            if len(rargs) < nargs:
-                if nargs == 1:
-                    self.error("%s option requires an argument" % opt)
-                else:
-                    self.error("%s option requires %d arguments"
-                               % (opt, nargs))
-            elif nargs == 1:
-                value = rargs.pop(0)
-            else:
-                value = tuple(rargs[0:nargs])
-                del rargs[0:nargs]
-
-        elif had_explicit_value:
-            self.error("%s option does not take a value" % opt)
-
-        else:
-            value = None
-
-        option.process(opt, value, values, self)
diff --git a/src/ovirtcli/main.py b/src/ovirtcli/main.py
index 20aac92..39149e4 100644
--- a/src/ovirtcli/main.py
+++ b/src/ovirtcli/main.py
@@ -24,7 +24,7 @@
     ############################## MAIN #################################
 def main():
     parser = create(OvirtCliOptionParser)
-    context = OvirtCliExecutionContext(sys.argv, parser)
+    context = OvirtCliExecutionContext(sys.argv)
     shell = EngineShell(context, parser)
 
     if len(sys.argv) > 1:


-- 
To view, visit http://gerrit.ovirt.org/36256
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic08f2849ef6209819c4b72c26606ec5be1f8248c
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine-cli
Gerrit-Branch: master
Gerrit-Owner: Juan Hernandez <juan.hernan...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to