retter – REverse TemplaTing ExtractoR
Allows you to extract values (to JSON) out of a file or stdin based on a mustach template definition.
Quick start
- Install retter:
npm i -g retter
- Define template (mustache Syntax)
- Get your content (save as file or prepare to pipe into
retter
) - Run retter
- Stdin:
cat content.file | retter template.mustache
- File:
retter template.mustache content.txt
Use case
retter
is supposed to save you some headache when parsing command line output or files. Using awk
, sed
, grep
and all their other friends is suitable for nerve-racking hours of trial and error – if you want to get this stuff done fast use retter
.
Typical use case: Some awesome command line tool generates the very same (but different) output every time (like every freakin' CI automation does). Now you want to get the data / values extracted from the output for further processing / analysis / whatever.
Further processing
You can use jq, a lightweight and flexible command-line JSON processor, to process the results even further.
retter examples/template examples/content | jq '[.issues]'
Example (parsing a Sonarlint output)
Template
------------- SonarLint Report -------------
{{issues}} issues ({{files}} files analyzed)
{{blocker}} blocker
{{critical}} critical
{{major}} major
{{minor}} minor
{{info}} info
-------------------------------------------
Content
------------- SonarLint Report -------------
11280 issues (3577 files analyzed)
131 blocker
1170 critical
5984 major
3951 minor
44 info
-------------------------------------------
Command
$ retter examples/template examples/content