Skip to content

Latest commit

 

History

History
43 lines (38 loc) · 2.21 KB

output.md

File metadata and controls

43 lines (38 loc) · 2.21 KB

Output

Adapters

Output adapter is responsible for rendering the output in a specific way using formatters (see below). Hammer comes with following adapters:

  • base - simple output, structured records
  • table - records printed in tables, ideal for printing lists of records
  • csv - comma separated output, ideal for scripting and grepping
  • yaml - YAML output
  • json - JSON output
  • silent - no output, used for testing

Formatters

Formatter is a bit of code that can modify a representation of a field during output rendering. Formatter is registered for specific field type. Each field type can have multiple formatters.

  • ColorFormatter - colors data with a specific color
  • DateFormatter - formats a date string with %Y/%m/%d %H:%M:%S style
  • ListFormatter - formats an array of data with csv style
  • KeyValueFormatter - formats a hash with key => value style
  • BooleanFormatter - converts 1/0/true/false/"" to "yes"/"no"
  • LongTextFormatter - adds a new line at the start of the data string
  • InlineTextFormatter - removes all new lines from data string
  • MultilineTextFormatter - splits a long data string to fixed size chunks with indentation

Formatter/Adapter features

Currently used formatter (or adapter) features are of two kinds. The first one help us to align by structure of the output:

  • :serialized - means the fields are serialized into a string (table, csv, base adapters)
  • :structured - means the output is structured (yaml, json adapters)
  • :inline - means that the value will be rendered into single line without newlines (table, csv adapters)
  • :multiline - means that the properly indented value will be printed over multiple lines (base adapter)

The other kind serves to distinguish the cases where we can use the xterm colors to improve the output:

  • :rich_text - means we can use the xterm colors (table, base adapters)
  • :plain_text - unused yet

All the features the formatter has need to match (be present in) the adapter's features. Otherwise the formatter won't apply.