From 6e53d03c69581982d341f591bfc3a35ec7f324d9 Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Wed, 21 Jan 2009 13:59:55 -0700 Subject: Command.takes_options and Command.takes_args class attributes can now also be a callable --- ipalib/frontend.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'ipalib/frontend.py') diff --git a/ipalib/frontend.py b/ipalib/frontend.py index b30205fe8..800bb43b3 100644 --- a/ipalib/frontend.py +++ b/ipalib/frontend.py @@ -312,23 +312,33 @@ class Command(plugable.Plugin): def get_args(self): """ - Return iterable with arguments for Command.args namespace. + Iterate through parameters for ``Command.args`` namespace. Subclasses can override this to customize how the arguments are determined. For an example of why this can be useful, see `ipalib.crud.Mod`. """ - return self.takes_args + if callable(self.takes_args): + args = self.takes_args() + else: + args = self.takes_args + for arg in args: + yield arg def get_options(self): """ - Return iterable with options for Command.options namespace. + Iterate through parameters for ``Command.options`` namespace. Subclasses can override this to customize how the options are determined. For an example of why this can be useful, see `ipalib.crud.Mod`. """ - return self.takes_options + if callable(self.takes_options): + options = self.takes_options() + else: + options = self.takes_options + for option in options: + yield option def __create_args(self): """ -- cgit