]> www.infradead.org Git - users/dhowells/kafs-utils.git/commitdiff
Provide generic check for non-combinable parameters
authorDavid Howells <dhowells@redhat.com>
Wed, 9 Apr 2014 14:43:22 +0000 (15:43 +0100)
committerDavid Howells <dhowells@redhat.com>
Wed, 9 Apr 2014 14:43:22 +0000 (15:43 +0100)
Provide generic check for non-combinable parameters in command py files.  A
list of tuples of pairs of argument names that don't interact is provided by
the name cant_combine_arguments as a global var.

Signed-off-by: David Howells <dhowells@redhat.com>
suite/commands/vos/listvldb.py
suite/main.py

index 2bbe7828452c85f4b3d67b0d3b5e472ffd050daf..a9fd1533871ad0ea9ae9df9a9473f82e8eef5c4c 100644 (file)
@@ -43,6 +43,14 @@ command_arguments = [
     [ "noresolve",      get_dummy,              "fn" ],
 ]
 
+cant_combine_arguments = [
+    ( "cell",           "localauth" ),
+    ( "noauth",         "localauth" ),
+    ( "name",           "server" ),
+    ( "name",           "partition" ),
+    ( "name",           "locked" ),
+]
+
 description = r"""
 Displays a volume's VLDB entry
 """
@@ -114,16 +122,11 @@ def main(params):
     quiet = "quiet" in params
 
     if "name" in params:
-        if "server" in params or "partition" in params or "locked" in params:
-            raise RuntimeError("Can't combine -name with -server, -partition or -locked")
         ret = kafs.VL_GetEntryByName(z_conn, params["name"][0])
         vldb = ret.entry
         print_record(params, vldb)
         return
 
-    if "name" in params:
-        raise RuntimeError("Can't combine -server, -partition or -locked with -name")
-
     attributes = kafs.VldbListByAttributes()
     attributes.Mask = 0
 
index 9a6cb2a6f106ff6b7a1be54105b46110f634f6d3..aae8f838ee6e7b58d9bb298aa955bf7d51e40e26 100644 (file)
@@ -154,6 +154,11 @@ def _main():
     # Parse the parameters
     params = afs.argparse.parse_arguments(sys.argv[1:], command.command_arguments)
 
+    for i in command.cant_combine_arguments:
+        if i[0] in params and i[1] in params:
+            print("Can't combine -" + i[0], "with -" + i[1], file=sys.stderr)
+            sys.exit(2)
+
     # Stick in the default cell if there isn't one
     if "cell" not in params:
         from afs.lib.cell import cell