open-sauced / pizza-cli

A CLI for all things OpenSauced
MIT License
39 stars 11 forks source link

Feature: Support `--output/-o` flag globally for yaml, json, and csv outputs #42

Open jpmcb opened 1 year ago

jpmcb commented 1 year ago

Type of feature

🍕 Feature

Current behavior

There's no great way to "save" contributions besides piping the table output through standard out to a file:

❯ pizza insights contributors https://github.com/open-sauced/api > my-api-stats.txt
❯ cat my-api-stats.txt

 Repository URL        https://github.com/open-sauced/api
 New contributors      3
 Recent contributors   8
 Alumni contributors   4
 Repeat contributors   5

That works great, but the our output table isn't really standardized and doesn't allow for much composability with other CLI or data tools.

We should aim to support 3 formats wherever possible: yaml, json, and csv.

Suggested solution

Add a --output/-o flag that accepts yaml, json, or csv

❯ pizza insights contributors https://github.com/open-sauced/api -o csv
Repository URL, New contributors, Recent contributors, Alumni contributors, Repeat contributors, Repeat contributors
https://github.com/open-sauced/api, 3, 8, 4, 5

this can then be piped to a .csv file and loaded into common programs like Excel.

The yaml and json outputs are alittle more straightforward:

❯ pizza insights contributors https://github.com/open-sauced/api -o
---
Repository URL: https://github.com/open-sauced/api
New contributors: 3
Recent contributors: 8
Alumni contributors: 4
Repeat contributors: 5
❯ pizza insights contributors https://github.com/open-sauced/api -o
{
    "Repository URL": "https: //github.com/open-sauced/api",
    "New contributors": 3,
    "Recent contributors": 8,
    "Alumni contributors": 4,
    "Repeat contributors": 5
}

Additional context

No response

Code of Conduct

Contributing Docs

cecobask commented 1 year ago

The groundwork for this functionality can be found in this pull request: https://github.com/open-sauced/pizza-cli/pull/38 I've implemented the output options (table, json, yaml) for all subcommands of pizza insights. The only thing missing as of now is support for csv output.