diff options
-rw-r--r-- | ipalib/frontend.py | 2 | ||||
-rw-r--r-- | ipalib/plugins/f_misc.py | 24 | ||||
-rw-r--r-- | tests/test_ipalib/test_frontend.py | 10 |
3 files changed, 14 insertions, 22 deletions
diff --git a/ipalib/frontend.py b/ipalib/frontend.py index 446384a3a..3ae143ef3 100644 --- a/ipalib/frontend.py +++ b/ipalib/frontend.py @@ -793,7 +793,7 @@ class LocalOrRemote(Command): """ takes_options = ( - Param('server', type=ipa_types.Bool(), default=False, + Param('server?', type=ipa_types.Bool(), default=False, doc='Forward to server instead of running locally', ), ) diff --git a/ipalib/plugins/f_misc.py b/ipalib/plugins/f_misc.py index 05fd6d525..6988d6f87 100644 --- a/ipalib/plugins/f_misc.py +++ b/ipalib/plugins/f_misc.py @@ -21,44 +21,36 @@ Misc frontend plugins. """ -from ipalib import api, Command, Param, Bool +from ipalib import api, LocalOrRemote # FIXME: We should not let env return anything in_server # when mode == 'production'. This would allow an attacker to see the # configuration of the server, potentially revealing compromising # information. However, it's damn handy for testing/debugging. -class env(Command): +class env(LocalOrRemote): """Show environment variables""" takes_args = ('variables*',) - takes_options = ( - Param('server?', type=Bool(), default=False, - doc='Show environment variables of server', - ), - ) - - def run(self, variables, **options): - if options['server'] and not self.env.in_server: - return self.forward(variables) - return self.execute(variables) - - def find_keys(self, variables): + def __find_keys(self, variables): for key in variables: if key in self.env: yield (key, self.env[key]) - def execute(self, variables): + def execute(self, variables, **options): if variables is None: return tuple( (key, self.env[key]) for key in self.env ) - return tuple(self.find_keys(variables)) + return tuple(self.__find_keys(variables)) def output_for_cli(self, textui, result, variables, **options): if len(result) == 0: return + if len(result) == 1: + textui.print_keyval(result) + return textui.print_name(self.name) textui.print_keyval(result) textui.print_count(result, '%d variable', '%d variables') diff --git a/tests/test_ipalib/test_frontend.py b/tests/test_ipalib/test_frontend.py index 45c6bb80d..771fdb911 100644 --- a/tests/test_ipalib/test_frontend.py +++ b/tests/test_ipalib/test_frontend.py @@ -811,7 +811,7 @@ class test_LocalOrRemote(ClassChecker): assert list(o.args) == [] assert list(o.options) == ['server'] op = o.options.server - assert op.required is True + assert op.required is False assert op.default is False def test_run(self): @@ -832,8 +832,8 @@ class test_LocalOrRemote(ClassChecker): api.register(example) api.finalize() cmd = api.Command.example - assert cmd() == ('execute', (None,), dict(server=False)) - assert cmd('var') == ('execute', (u'var',), dict(server=False)) + assert cmd() == ('execute', (None,), dict(server=None)) + assert cmd('var') == ('execute', (u'var',), dict(server=None)) assert cmd(server=True) == ('forward', (None,), dict(server=True)) assert cmd('var', server=True) == \ ('forward', (u'var',), dict(server=True)) @@ -843,8 +843,8 @@ class test_LocalOrRemote(ClassChecker): api.register(example) api.finalize() cmd = api.Command.example - assert cmd() == ('execute', (None,), dict(server=False)) - assert cmd('var') == ('execute', (u'var',), dict(server=False)) + assert cmd() == ('execute', (None,), dict(server=None)) + assert cmd('var') == ('execute', (u'var',), dict(server=None)) assert cmd(server=True) == ('execute', (None,), dict(server=True)) assert cmd('var', server=True) == \ ('execute', (u'var',), dict(server=True)) |