A small addition that adds a --format flag with two options: table which is the existing functionality and json which formats the output as a JSON object to facilitate automation and integration with other tools.
Here's a small demo of why I did this, running the tool on itself:
> cargo run -- --format=json
Compiling loc v0.5.0 (/Users/barnabykeene/Desktop/loc)
Finished dev [unoptimized + debuginfo] target(s) in 4.34s
Running `target/debug/loc --format=json`
{"Bourne Shell":{"files":3,"count":{"code":59,"comment":7,"blank":18,"lines":84}},"Haskell":{"files":1,"count":{"code":2,"comment":8,"blank":4,"lines":14}},"Terraform":{"files":1,"count":{"code":65,"comment":11,"blank":13,"lines":89}},"Ada":{"files":2,"count":{"code":32,"comment":9,"blank":12,"lines":53}},"Solidity":{"files":1,"count":{"code":10,"comment":3,"blank":3,"lines":16}},"Lua":{"files":2,"count":{"code":169351,"comment":193544,"blank":24193,"lines":387088}},"Groovy":{"files":1,"count":{"code":6,"comment":10,"blank":1,"lines":17}},"OCaml":{"files":1,"count":{"code":3,"comment":6,"blank":4,"lines":13}},"PowerShell":{"files":2,"count":{"code":15,"comment":9,"blank":8,"lines":32}},"Ruby":{"files":1,"count":{"code":2,"comment":2,"blank":0,"lines":4}},"Handlebars":{"files":1,"count":{"code":2,"comment":2,"blank":0,"lines":4}},"Rust":{"files":4,"count":{"code":1260,"comment":60,"blank":134,"lines":1454}},"YAML":{"files":1,"count":{"code":57,"comment":19,"blank":13,"lines":89}},"Python":{"files":1,"count":{"code":2,"comment":2,"blank":2,"lines":6}},"Toml":{"files":1,"count":{"code":24,"comment":0,"blank":4,"lines":28}},"C":{"files":4,"count":{"code":470,"comment":155,"blank":75,"lines":700}},"Markdown":{"files":2,"count":{"code":280,"comment":0,"blank":42,"lines":322}},"Gherkin":{"files":1,"count":{"code":8,"comment":2,"blank":2,"lines":12}},"Zig":{"files":1,"count":{"code":5,"comment":2,"blank":2,"lines":9}},"Reason":{"files":1,"count":{"code":3,"comment":6,"blank":4,"lines":13}},"Nix":{"files":1,"count":{"code":3,"comment":3,"blank":2,"lines":8}}}
Pure JSON is ugly, I considered making it pretty but decided it would be pointless since this feature is intended for piping to other tools for automation etc.
A small addition that adds a --format flag with two options:
table
which is the existing functionality andjson
which formats the output as a JSON object to facilitate automation and integration with other tools.Here's a small demo of why I did this, running the tool on itself:
Pure JSON is ugly, I considered making it pretty but decided it would be pointless since this feature is intended for piping to other tools for automation etc.
Such as
jq
:Also, if you're using NuShell then you can play with the data a bit more!