summaryrefslogtreecommitdiffstats
path: root/ipalib/public.py
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2008-09-09 23:46:16 +0000
committerJason Gerard DeRose <jderose@redhat.com>2008-09-09 23:46:16 +0000
commit349fc660e796841a3d78b82bf4fa195a228da4c4 (patch)
tree621b35c012f9e89070bb8dc4cfd8b3f8ac011fbe /ipalib/public.py
parent0453aa465f8371aa4baea5c06adad42481553e0a (diff)
downloadfreeipa.git-349fc660e796841a3d78b82bf4fa195a228da4c4.tar.gz
freeipa.git-349fc660e796841a3d78b82bf4fa195a228da4c4.tar.xz
freeipa.git-349fc660e796841a3d78b82bf4fa195a228da4c4.zip
275: Added Command.__check_args(); added basic unit tests for Command.args instance attribute
Diffstat (limited to 'ipalib/public.py')
-rw-r--r--ipalib/public.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/ipalib/public.py b/ipalib/public.py
index b22eff0e..003e0d72 100644
--- a/ipalib/public.py
+++ b/ipalib/public.py
@@ -214,12 +214,39 @@ class Command(plugable.Plugin):
options = tuple()
takes_args = tuple()
+ def __init__(self):
+ self.args = plugable.NameSpace(self.__check_args(), sort=False)
+
def get_args(self):
return self.takes_args
def get_options(self):
return self.options
+ def __check_args(self):
+ optional = False
+ multivalue = False
+ for arg in self.get_args():
+ if type(arg) is str:
+ arg = Option(arg, '', ipa_types.Unicode(), required=True)
+ elif not isinstance(arg, Option):
+ raise TypeError(
+ 'arg: need %r or %r; got %r' % (str, Option, arg)
+ )
+ if optional and arg.required:
+ raise ValueError(
+ '%s: required argument after optional' % arg.name
+ )
+ if multivalue:
+ raise ValueError(
+ '%s: only final argument can be multivalue' % arg.name
+ )
+ if not arg.required:
+ optional = True
+ if arg.multivalue:
+ multivalue = True
+ yield arg
+
def __get_Option(self):
"""
Returns the NameSpace containing the Option instances.