Restore correct clitools support for variable argument count 84/76484/2
authorJames Harrison <00jamesh@gmail.com>
Fri, 7 Apr 2017 17:18:14 +0000 (18:18 +0100)
committerDave Rigby <daver@couchbase.com>
Fri, 7 Apr 2017 17:37:18 +0000 (17:37 +0000)
This was broken by failing to account for defaults being provided to
arguments.

Change-Id: I8058b12052c3befe5fe32684decaa88c659695d4
Reviewed-on: http://review.couchbase.org/76484
Tested-by: Build Bot <build@couchbase.com>
Reviewed-by: Dave Rigby <daver@couchbase.com>
Tested-by: Dave Rigby <daver@couchbase.com>
management/cli_auth_utils.py

index dcf196f..4548004 100644 (file)
@@ -14,20 +14,23 @@ def cmd_decorator(f):
     def g(*args, **kwargs):
         mc = args[0]
         spec = inspect.getargspec(f)
-        n = len(spec.args)
+        max = len(spec.args)
+        defaults = len(spec.defaults) if spec.defaults else 0
+        min = max - defaults
+
+        if len(args) < min:
+            print >> sys.stderr, ("Error: too few arguments - command "
+                                  "expected a minimum of %s but was passed "
+                                  "%s: %s"
+                                  % (min - 1, len(args) - 1, list(args[1:])))
+            sys.exit(2)
 
         if spec.varargs is None:
-            if len(args) > n:
+            if len(args) > max:
                 print >> sys.stderr, ("Error: too many arguments - command "
                                       "expected a maximum of %s but was passed "
                                       "%s: %s"
-                                      % (n - 1, len(args) - 1, list(args[1:])))
-                sys.exit(2)
-            elif len(args) < n:
-                print >> sys.stderr, ("Error: too few arguments - command "
-                                      "expected a minimum of %s but was passed "
-                                      "%s: %s"
-                                      % (n - 1, len(args) - 1, list(args[1:])))
+                                      % (max - 1, len(args) - 1, list(args[1:])))
                 sys.exit(2)
 
         bucket = kwargs.get('bucketName', None) or 'default'