Add value format for list command
The value format for the show command is very handy for shell scripting and a value format for the list command would be just as handy. It will allow command substitution and piping like: os container list --format value | grep tmp | while read NAME do os container delete $NAME done Change-Id: If9784c27d689073e9145b2cb8077ac604025a4c3
This commit is contained in:
parent
4abf524be5
commit
24120da1df
|
@ -1,14 +1,22 @@
|
|||
"""Output formatters values only
|
||||
"""
|
||||
|
||||
import six
|
||||
|
||||
from .base import ListFormatter
|
||||
from .base import SingleFormatter
|
||||
|
||||
|
||||
class ValueFormatter(SingleFormatter):
|
||||
class ValueFormatter(ListFormatter, SingleFormatter):
|
||||
|
||||
def add_argument_group(self, parser):
|
||||
pass
|
||||
|
||||
def emit_list(self, column_names, data, stdout, parsed_args):
|
||||
for row in data:
|
||||
stdout.write(' '.join(map(six.text_type, row)) + u'\n')
|
||||
return
|
||||
|
||||
def emit_one(self, column_names, data, stdout, parsed_args):
|
||||
for value in data:
|
||||
stdout.write('%s\n' % str(value))
|
||||
|
|
|
@ -13,3 +13,16 @@ def test_value_formatter():
|
|||
sf.emit_one(c, d, output, None)
|
||||
actual = output.getvalue()
|
||||
assert expected == actual
|
||||
|
||||
|
||||
def test_value_list_formatter():
|
||||
sf = value.ValueFormatter()
|
||||
c = ('a', 'b', 'c')
|
||||
d1 = ('A', 'B', 'C')
|
||||
d2 = ('D', 'E', 'F')
|
||||
data = [d1, d2]
|
||||
expected = 'A B C\nD E F\n'
|
||||
output = StringIO()
|
||||
sf.emit_list(c, data, output, None)
|
||||
actual = output.getvalue()
|
||||
assert expected == actual
|
||||
|
|
Loading…
Reference in New Issue