From 7de450363bc56a747a495803d56cc7c4d1323293 Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Wed, 10 Sep 2008 15:14:26 +0000 Subject: 282: Added Command.__check_options() method; added unit tests for Command.options instance attribute --- ipalib/public.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'ipalib/public.py') diff --git a/ipalib/public.py b/ipalib/public.py index 7f1929f4..7dfcd176 100644 --- a/ipalib/public.py +++ b/ipalib/public.py @@ -227,6 +227,7 @@ class Command(plugable.Plugin): 'smart_option_order', 'Option', 'args', + 'options', )) __Option = None takes_options = tuple() @@ -234,6 +235,7 @@ class Command(plugable.Plugin): def __init__(self): self.args = plugable.NameSpace(self.__check_args(), sort=False) + self.options = plugable.NameSpace(self.__check_options(), sort=False) def get_args(self): return self.takes_args @@ -265,6 +267,16 @@ class Command(plugable.Plugin): multivalue = True yield arg + def __check_options(self): + for option in self.get_options(): + if type(option) is str: + option = generate_argument(option) + elif not isinstance(option, Option): + raise TypeError( + 'option: need %r or %r; got %r' % (str, Option, option) + ) + yield option + def __get_Option(self): """ Returns the NameSpace containing the Option instances. -- cgit