Revision 1757c616 kamaki/cli/commands/__init__.py

b/kamaki/cli/commands/__init__.py
32 32
# or implied, of GRNET S.A.command
33 33

  
34 34
from kamaki.cli.logger import get_logger
35
from kamaki.cli.utils import (
36
    print_json, print_items, filter_dicts_by_dict, stdout)
35
from kamaki.cli.utils import print_json, print_items, filter_dicts_by_dict
37 36
from kamaki.cli.argument import FlagArgument, ValueArgument
37
from sys import stdin, stdout
38 38

  
39 39
log = get_logger(__name__)
40 40

  
......
60 60

  
61 61
class _command_init(object):
62 62

  
63
    def __init__(self, arguments={}, auth_base=None, cloud=None):
63
    def __init__(
64
            self,
65
            arguments={}, auth_base=None, cloud=None, _in=None, _out=None):
66
        self._in, self._out = _in or stdin, _out or stdout
64 67
        if hasattr(self, 'arguments'):
65 68
            arguments.update(self.arguments)
66 69
        if isinstance(self, _optional_output_cmd):
......
209 212

  
210 213
    def _optional_output(self, r):
211 214
        if self['json_output']:
212
            print_json(r)
215
            print_json(r, out=self._out)
213 216
        elif self['with_output']:
214
            print_items([r] if isinstance(r, dict) else r)
217
            print_items([r] if isinstance(r, dict) else r, out=self._out)
215 218

  
216 219

  
217 220
class _optional_json(object):
......
220 223
        json_output=FlagArgument('show headers in json', ('-j', '--json'))
221 224
    )
222 225

  
223
    def _print(
224
            self, output,
225
            print_method=print_items, out=stdout,
226
            **print_method_kwargs):
226
    def _print(self, output, print_method=print_items, **print_method_kwargs):
227 227
        if self['json_output']:
228
            print_json(output, out=out)
228
            print_json(output, out=self._out)
229 229
        else:
230
            print_method(output, out=out, **print_method_kwargs)
230
            print_method(output, out=self._out, **print_method_kwargs)
231 231

  
232 232

  
233 233
class _name_filter(object):

Also available in: Unified diff