Juan Hernandez has uploaded a new change for review.

Change subject: cli: Check that the --max option has a value
......................................................................

cli: Check that the --max option has a value

Currently we don't check that the --max option has a value, if the value
isn't given it is silently ignored. This patch changes the CLI so that
it will present an error message when no value is given.

Change-Id: I0801c60d33b5e30f8844659df98e6d8405f34167
Signed-off-by: Juan Hernandez <[email protected]>
---
M src/cli/messages.py
M src/ovirtcli/command/command.py
M src/ovirtcli/command/list.py
3 files changed, 13 insertions(+), 0 deletions(-)


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

diff --git a/src/cli/messages.py b/src/cli/messages.py
index c4d0f9a..444ea25 100644
--- a/src/cli/messages.py
+++ b/src/cli/messages.py
@@ -55,6 +55,7 @@
         INVALID_URL_SEGMENT = '"%s" is invalid url format. valid format is 
http[s]://server:port/api.'
         MISSING_CONFIGURATION_VARIABLE = 'missing configuration variable: %s.'
         UNSUPPORTED_ATTRIBUTE = 'object construction failure, this could 
happen if you using unsupported option, please see help for the given command 
for more details.'
+        OPTION_REQUIRES_VALUE = 'option "--%s" requires a value.'
     class Warning():
         CANNOT_FETCH_HOST_CERT_SUBJECT = 'could not fetch host certificate 
info.'
         CANNOT_FETCH_HOST_CERT_SUBJECT_LEGACY_SDK = 'could not fetch host 
certificate info cause used backend/sdk does not support it.'
diff --git a/src/ovirtcli/command/command.py b/src/ovirtcli/command/command.py
index 9b9b6dc..1c374c5 100644
--- a/src/ovirtcli/command/command.py
+++ b/src/ovirtcli/command/command.py
@@ -259,6 +259,11 @@
                 mopts[k if not k.startswith('--') else k[2:]] = v
         kw.update(mopts)
 
+        # Check that all the options that require a value actually have it:
+        for k, v in mopts.iteritems():
+            if v is None and self._is_value_required(k):
+                self.error(Messages.Error.OPTION_REQUIRES_VALUE % k)
+
         return query, kw
 
 
@@ -495,3 +500,7 @@
         """INTERNAL: return a list of type actions."""
 
         return MethodHelper.get_object_methods(obj, exceptions=['delete', 
'update'])
+
+    def _is_value_required(self, option):
+        """Checks if the given option requires a value."""
+        return False
diff --git a/src/ovirtcli/command/list.py b/src/ovirtcli/command/list.py
index e0aacf3..830b1f0 100644
--- a/src/ovirtcli/command/list.py
+++ b/src/ovirtcli/command/list.py
@@ -196,3 +196,6 @@
 
             helptext = self.format_help(helptext, subst)
             self.write(helptext)
+
+    def _is_value_required(self, option):
+        return option in ['max']


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0801c60d33b5e30f8844659df98e6d8405f34167
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine-cli
Gerrit-Branch: master
Gerrit-Owner: Juan Hernandez <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to