diff options
author | Jason Gerard DeRose <jderose@redhat.com> | 2008-08-11 00:21:12 +0000 |
---|---|---|
committer | Jason Gerard DeRose <jderose@redhat.com> | 2008-08-11 00:21:12 +0000 |
commit | 879133d28a2da2d675d72a3f4e178f5bc4c82594 (patch) | |
tree | 4117f9be6bf86371c6fd15faa62f11b6515dca8c /ipalib/public.py | |
parent | f6b69a590500cf8c141545a1f95d59817eb5a27e (diff) | |
download | freeipa.git-879133d28a2da2d675d72a3f4e178f5bc4c82594.tar.gz freeipa.git-879133d28a2da2d675d72a3f4e178f5bc4c82594.tar.xz freeipa.git-879133d28a2da2d675d72a3f4e178f5bc4c82594.zip |
105: Added a default implementation of cmd.get_options; added corresponding unit tests
Diffstat (limited to 'ipalib/public.py')
-rw-r--r-- | ipalib/public.py | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/ipalib/public.py b/ipalib/public.py index 92dc77af..baa1496a 100644 --- a/ipalib/public.py +++ b/ipalib/public.py @@ -23,6 +23,7 @@ and UI all use. """ import re +import inspect import plugable import errors @@ -134,7 +135,8 @@ class cmd(plugable.Plugin): 'opt', )) - __opt = None + __options = None + option_classes = tuple() def get_doc(self, _): """ @@ -149,19 +151,21 @@ class cmd(plugable.Plugin): def get_options(self): """ - Returns iterable with opt_proxy objects used to create the opt - NameSpace when __get_opt() is called. + Returns iterable with option proxy objects used to create the option + NameSpace when __get_option() is called. """ - raise NotImplementedError('%s.get_options()' % self.name) + for cls in self.option_classes: + assert inspect.isclass(cls) + yield plugable.Proxy(option, cls()) - def __get_opt(self): + def __get_options(self): """ - Returns the NameSpace containing opt_proxy objects. + Returns the NameSpace containing the option proxy objects. """ - if self.__opt is None: - self.__opt = plugable.NameSpace(self.get_options()) + if self.__options is None: + self.__options = plugable.NameSpace(self.get_options()) return self.__opt - opt = property(__get_opt) + options = property(__get_options) def normalize_iter(self, kw): for (key, value) in kw.items(): |