diff options
author | Terry Howe <terrylhowe@gmail.com> | 2014-03-14 10:15:29 -0600 |
---|---|---|
committer | Terry Howe <terrylhowe@gmail.com> | 2014-03-17 15:07:28 -0600 |
commit | 5503d3d0068484b7428e223011733667eb4e347f (patch) | |
tree | 6d0975b4597083bed713237432231f9f9492decd | |
parent | b9f04372f0ef7413ec4537122d700544a27445e5 (diff) | |
download | cliff-5503d3d0068484b7428e223011733667eb4e347f.tar.gz |
Add value only output formattter
It may be useful to have a value only output formatter to perform operationgs like:
TOKEN=$(openstack token create -c id -f value)
Rather than:
eval $(openstack token create -c id -f shell)
TOKEN="${id}"
Change-Id: I7bda3cc1a1d154a05e8e31eed564dae1e82066d6
Closes-Bug: #1292578
-rw-r--r-- | cliff/formatters/value.py | 15 | ||||
-rw-r--r-- | cliff/tests/test_formatters_value.py | 15 | ||||
-rw-r--r-- | setup.cfg | 1 |
3 files changed, 31 insertions, 0 deletions
diff --git a/cliff/formatters/value.py b/cliff/formatters/value.py new file mode 100644 index 0000000..9910319 --- /dev/null +++ b/cliff/formatters/value.py @@ -0,0 +1,15 @@ +"""Output formatters values only +""" + +from .base import SingleFormatter + + +class ValueFormatter(SingleFormatter): + + def add_argument_group(self, parser): + pass + + def emit_one(self, column_names, data, stdout, parsed_args): + for value in data: + stdout.write('%s\n' % str(value)) + return diff --git a/cliff/tests/test_formatters_value.py b/cliff/tests/test_formatters_value.py new file mode 100644 index 0000000..25fb23d --- /dev/null +++ b/cliff/tests/test_formatters_value.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python +from six import StringIO + +from cliff.formatters import value + + +def test_value_formatter(): + sf = value.ValueFormatter() + c = ('a', 'b', 'c', 'd') + d = ('A', 'B', 'C', '"no escape me"') + expected = 'A\nB\nC\n"no escape me"\n' + output = StringIO() + sf.emit_one(c, d, output, None) + actual = output.getvalue() + assert expected == actual @@ -33,6 +33,7 @@ cliff.formatter.list = cliff.formatter.show = table = cliff.formatters.table:TableFormatter shell = cliff.formatters.shell:ShellFormatter + value = cliff.formatters.value:ValueFormatter cliff.formatter.completion = bash = cliff.complete:CompleteBash |