summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTerry Howe <terrylhowe@gmail.com>2014-03-14 10:15:29 -0600
committerTerry Howe <terrylhowe@gmail.com>2014-03-17 15:07:28 -0600
commit5503d3d0068484b7428e223011733667eb4e347f (patch)
tree6d0975b4597083bed713237432231f9f9492decd
parentb9f04372f0ef7413ec4537122d700544a27445e5 (diff)
downloadcliff-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.py15
-rw-r--r--cliff/tests/test_formatters_value.py15
-rw-r--r--setup.cfg1
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
diff --git a/setup.cfg b/setup.cfg
index e019b4f..b7f1529 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -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