update formatter documentation

This commit is contained in:
Doug Hellmann
2012-05-06 21:22:14 -04:00
parent 88c5454768
commit 03a954b867
2 changed files with 96 additions and 44 deletions

View File

@@ -43,6 +43,31 @@ further manipulation.
"Makefile",5569
"source",408
html
----
The ``html`` formatter uses tablib_ to produce HTML output as a table.
::
(.venv)$ cliffdemo files -f html
<table>
<thead>
<tr><th>Name</th>
<th>Size</th></tr>
</thead>
<tr><td>build</td>
<td>136</td></tr>
<tr><td>cliffdemo.log</td>
<td>3252</td></tr>
<tr><td>Makefile</td>
<td>5569</td></tr>
<tr><td>requirements.txt</td>
<td>33</td></tr>
<tr><td>source</td>
<td>782</td></tr>
</table>
json
----
@@ -90,34 +115,6 @@ sequence of mappings.
- {Name: requirements.txt, Size: 33}
- {Name: source, Size: 816}
.. _tablib: https://github.com/kennethreitz/tablib
html
----
The ``html`` formatter uses tablib_ to produce HTML output as a
sequence of mappings.
::
(.venv)$ cliffdemo files -f html
<table>
<thead>
<tr><th>Name</th>
<th>Size</th></tr>
</thead>
<tr><td>build</td>
<td>136</td></tr>
<tr><td>cliffdemo.log</td>
<td>3252</td></tr>
<tr><td>Makefile</td>
<td>5569</td></tr>
<tr><td>requirements.txt</td>
<td>33</td></tr>
<tr><td>source</td>
<td>782</td></tr>
</table>
Creating Your Own Formatter
---------------------------
@@ -127,3 +124,5 @@ another formatter with your program by subclassing from
:class:`cliff.formatters.base.ListFormatter` and registering the
plugin in the ``cliff.formatter.list`` namespace.
.. _tablib: https://github.com/kennethreitz/tablib

View File

@@ -27,26 +27,42 @@ commands. :class:`ShowOne` adds a command line switch to let the user
specify the formatter they want, so you don't have to do any extra
work in your application.
table
-----
html
----
The ``table`` formatter uses PrettyTable_ to produce output
formatted for human consumption.
.. _PrettyTable: http://code.google.com/p/prettytable/
The ``html`` formatter uses tablib_ to produce HTML output as a table.
::
(.venv)$ cliffdemo file setup.py
+---------------+--------------+
| Field | Value |
+---------------+--------------+
| Name | setup.py |
| Size | 5825 |
| UID | 502 |
| GID | 20 |
| Modified Time | 1335569964.0 |
+---------------+--------------+
(.venv)$ cliffdemo file -f html setup.py
<table>
<thead>
<tr><th>Field</th>
<th>Value</th></tr>
</thead>
<tr><td>Name</td>
<td>setup.py</td></tr>
<tr><td>Size</td>
<td>6373</td></tr>
<tr><td>UID</td>
<td>527</td></tr>
<tr><td>GID</td>
<td>501</td></tr>
<tr><td>Modified Time</td>
<td>1336353173.0</td></tr>
</table>
json
----
The ``json`` formatter uses tablib_ to produce JSON output.
::
(.venv)$ cliffdemo file -f json setup.py
[{"Field": "Name", "Value": "setup.py"}, {"Field": "Size",
"Value": 6373}, {"Field": "UID", "Value": 527}, {"Field": "GID",
"Value": 501}, {"Field": "Modified Time", "Value": 1336353173.0}]
shell
-----
@@ -68,6 +84,41 @@ parsing overhead in shell scripts.
(.venv)$ echo $example_size
5916
table
-----
The ``table`` formatter uses PrettyTable_ to produce output
formatted for human consumption.
.. _PrettyTable: http://code.google.com/p/prettytable/
::
(.venv)$ cliffdemo file setup.py
+---------------+--------------+
| Field | Value |
+---------------+--------------+
| Name | setup.py |
| Size | 5825 |
| UID | 502 |
| GID | 20 |
| Modified Time | 1335569964.0 |
+---------------+--------------+
yaml
----
The ``yaml`` formatter uses tablib_ to produce YAML output as a
sequence of mappings.
::
(.venv)$ cliffdemo file -f yaml setup.py
- {Field: Name, Value: setup.py}
- {Field: Size, Value: 6373}
- {Field: UID, Value: 527}
- {Field: GID, Value: 501}
- {Field: Modified Time, Value: 1336353173.0}
Creating Your Own Formatter
---------------------------
@@ -77,3 +128,5 @@ another formatter with your program by subclassing from
:class:`cliff.formatters.base.ShowFormatter` and registering the
plugin in the ``cliff.formatter.show`` namespace.
.. _tablib: https://github.com/kennethreitz/tablib