As discussed with Rob on IRC, this patch changes the
Command.get_output_params() method so that by default your
Command.output_params will be the same as your Command.params.

This make the behavior similar to how Method.get_output_params() fills
your Method.params with the params in the corresponding Object.params.

If you have args or options that you *don't* want in output_params, add
the 'no_output' flag, like this:

   Str('foo', flags=['no_output'])

This is similar to the 'no_create', 'no_update', and 'no_search' flags
for Method plugins.

If you need output that wont be in your args or options, add them in a
`has_output_params` tuple, like this:

    has_output_params = (
        'bar',
        'baz',
    )

I'll add docstrings in another patch, but this is blocking Rob, so I
made it a quickie.


 
>From 0ff22e4a0fa946e6011e77554fd55f005d40d8d2 Mon Sep 17 00:00:00 2001
From: Jason Gerard DeRose <jder...@redhat.com>
Date: Wed, 10 Feb 2010 21:15:47 -0700
Subject: [PATCH] Command.output_params not contains params in Command.params

---
 ipalib/frontend.py                 |    7 +++++++
 tests/test_ipalib/test_frontend.py |   27 +++++++++++++++++++++++++++
 2 files changed, 34 insertions(+), 0 deletions(-)

diff --git a/ipalib/frontend.py b/ipalib/frontend.py
index 1cc2ea2..0abb35b 100644
--- a/ipalib/frontend.py
+++ b/ipalib/frontend.py
@@ -810,6 +810,13 @@ class Command(HasParam):
     def get_output_params(self):
         for param in self._get_param_iterable('output_params', verb='has'):
             yield param
+        if self.params is None:
+            return
+        for param in self.params():
+            if 'no_output' in param.flags:
+                continue
+            yield param
+
 
     def output_for_cli(self, textui, output, *args, **options):
         if not isinstance(output, dict):
diff --git a/tests/test_ipalib/test_frontend.py b/tests/test_ipalib/test_frontend.py
index b5ecd05..7c67d6c 100644
--- a/tests/test_ipalib/test_frontend.py
+++ b/tests/test_ipalib/test_frontend.py
@@ -28,6 +28,7 @@ from ipalib.constants import TYPE_ERROR
 from ipalib.base import NameSpace
 from ipalib import frontend, backend, plugable, errors, parameters, config
 from ipalib import output
+from ipalib.parameters import Str
 
 def test_RULE_FLAG():
     assert frontend.RULE_FLAG == 'validation_rule'
@@ -654,6 +655,32 @@ class test_Command(ClassChecker):
             'nested', 'Subclass', 'world', 4, dict, tuple, nope
         )
 
+    def test_get_output_params(self):
+        """
+        Test the `ipalib.frontend.Command.get_output_params` method.
+        """
+        class example(self.cls):
+            has_output_params = (
+                'one',
+                'two',
+                'three',
+            )
+            takes_args = (
+                'foo',
+            )
+            takes_options = (
+                Str('bar', flags='no_output'),
+                'baz',
+            )
+
+        inst = example()
+        assert list(inst.get_output_params()) == ['one', 'two', 'three']
+        inst.finalize()
+        assert list(inst.get_output_params()) == [
+            'one', 'two', 'three', inst.params.foo, inst.params.baz
+        ]
+        assert list(inst.output_params) == ['one', 'two', 'three', 'foo', 'baz']
+
 
 class test_LocalOrRemote(ClassChecker):
     """
-- 
1.6.3.3

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to