aeolus-incubator/thor-cli — pull request #23 by jistr (2013-01-18 14:56:47+00:00)
Title: Output formatting

This is a large pull request but it's separated into independent coherent commits, plus the code has comments to explain purpose of classes and methods, so I hope it will not be hard to go through.

For human usage the behavior of CLI is the same as it was. Listings are tables aligned by spaces.

For machine usage (e.g. when output goes through a pipe), headers for lists are not printed and items in listings are just lines of text, where fields are separated by a tab character (configurability for the separation character will come in a future patch, the formatting code is ready for that).

Human vs. machine autodetection can be overriden by using `--format` option.

The code is also ready for field filtering, options for CLI (like `--fields=name,status`) and semi-ready for sorting (like `--sort-by=status`). In future patches we'll add those options for CLI.

The printing behavior is configurable, yet for common cases it can be almost automatic. It's just a matter of defining a presenter class (can be just a few lines of code), and then we get all the formatting, human vs. machine differences, (in the future also filtering, sorting).