summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2008-11-12 09:55:11 -0700
committerJason Gerard DeRose <jderose@redhat.com>2008-11-12 09:55:11 -0700
commitf04aaff97c9c8c22b36706f2c6d4de6f23d06b95 (patch)
tree64937c8d6f7d394f4c077585d124ecd0331b1f80
parent09161e399a61e2a548e9efb3c3abb2c7b47d5520 (diff)
downloadfreeipa-f04aaff97c9c8c22b36706f2c6d4de6f23d06b95.tar.gz
freeipa-f04aaff97c9c8c22b36706f2c6d4de6f23d06b95.tar.xz
freeipa-f04aaff97c9c8c22b36706f2c6d4de6f23d06b95.zip
output_for_cli signature is now output_for_cli(textui, result, *args, **options)
-rw-r--r--ipalib/cli.py3
-rw-r--r--ipalib/frontend.py16
-rw-r--r--ipalib/plugins/f_misc.py6
-rw-r--r--tests/test_ipalib/test_frontend.py19
4 files changed, 24 insertions, 20 deletions
diff --git a/ipalib/cli.py b/ipalib/cli.py
index 8878c212..d86647c6 100644
--- a/ipalib/cli.py
+++ b/ipalib/cli.py
@@ -535,7 +535,8 @@ class CLI(object):
try:
ret = cmd(**kw)
if callable(cmd.output_for_cli):
- cmd.output_for_cli(self.api.Backend.textui, ret, **kw)
+ (args, options) = cmd.params_2_args_options(kw)
+ cmd.output_for_cli(self.api.Backend.textui, ret, *args, **options)
return 0
except socket.error, e:
print e[1]
diff --git a/ipalib/frontend.py b/ipalib/frontend.py
index ce4168bc..56c4ea01 100644
--- a/ipalib/frontend.py
+++ b/ipalib/frontend.py
@@ -511,7 +511,7 @@ class Command(plugable.Plugin):
'options',
'params',
'args_to_kw',
- 'kw_to_args',
+ 'params_2_args_options',
'output_for_cli',
))
takes_options = tuple()
@@ -536,8 +536,8 @@ class Command(plugable.Plugin):
kw = self.convert(**kw)
kw.update(self.get_default(**kw))
self.validate(**kw)
- args = tuple(kw.pop(name) for name in self.args)
- return self.run(*args, **kw)
+ (args, options) = self.params_2_args_options(kw)
+ return self.run(*args, **options)
def args_to_kw(self, *values):
"""
@@ -569,11 +569,15 @@ class Command(plugable.Plugin):
else:
break
- def kw_to_args(self, **kw):
+ def params_2_args_options(self, params):
"""
- Map keyword into positional arguments.
+ Split params into (args, kw).
"""
- return tuple(kw.get(name, None) for name in self.args)
+ args = tuple(params.get(name, None) for name in self.args)
+ options = dict(
+ (name, params.get(name, None)) for name in self.options
+ )
+ return (args, options)
def normalize(self, **kw):
"""
diff --git a/ipalib/plugins/f_misc.py b/ipalib/plugins/f_misc.py
index 1acf1c99..05fd6d52 100644
--- a/ipalib/plugins/f_misc.py
+++ b/ipalib/plugins/f_misc.py
@@ -39,8 +39,8 @@ class env(Command):
),
)
- def run(self, variables, **kw):
- if kw['server'] and not self.env.in_server:
+ def run(self, variables, **options):
+ if options['server'] and not self.env.in_server:
return self.forward(variables)
return self.execute(variables)
@@ -56,7 +56,7 @@ class env(Command):
)
return tuple(self.find_keys(variables))
- def output_for_cli(self, textui, result, **kw):
+ def output_for_cli(self, textui, result, variables, **options):
if len(result) == 0:
return
textui.print_name(self.name)
diff --git a/tests/test_ipalib/test_frontend.py b/tests/test_ipalib/test_frontend.py
index 5a678b5b..75e098a4 100644
--- a/tests/test_ipalib/test_frontend.py
+++ b/tests/test_ipalib/test_frontend.py
@@ -735,18 +735,17 @@ class test_Command(ClassChecker):
e = raises(errors.ArgumentError, o.args_to_kw, 1, 2, 3)
assert str(e) == 'example takes at most 2 arguments'
- def test_kw_to_args(self):
+ def test_params_2_args_options(self):
"""
- Test the `ipalib.frontend.Command.kw_to_args` method.
+ Test the `ipalib.frontend.Command.params_2_args_options` method.
"""
- assert 'kw_to_args' in self.cls.__public__ # Public
- o = self.get_instance(args=('one', 'two?'))
- assert o.kw_to_args() == (None, None)
- assert o.kw_to_args(whatever='hello') == (None, None)
- assert o.kw_to_args(one='the one') == ('the one', None)
- assert o.kw_to_args(two='the two') == (None, 'the two')
- assert o.kw_to_args(whatever='hello', two='Two', one='One') == \
- ('One', 'Two')
+ assert 'params_2_args_options' in self.cls.__public__ # Public
+ o = self.get_instance(args=['one'], options=['two'])
+ assert o.params_2_args_options({}) == ((None,), dict(two=None))
+ assert o.params_2_args_options(dict(one=1)) == ((1,), dict(two=None))
+ assert o.params_2_args_options(dict(two=2)) == ((None,), dict(two=2))
+ assert o.params_2_args_options(dict(two=2, one=1)) == \
+ ((1,), dict(two=2))
def test_run(self):
"""