mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2024-12-25 08:21:05 -06:00
output_for_cli signature is now output_for_cli(textui, result, *args, **options)
This commit is contained in:
parent
09161e399a
commit
f04aaff97c
@ -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]
|
||||
|
@ -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):
|
||||
"""
|
||||
|
@ -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)
|
||||
|
@ -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):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user