nasirhjafri / libyear

A simple measure of software dependency freshness.
https://libyear.com/
131 stars 16 forks source link

feat: allow output to various machine-readable formats #34

Open dmaljovec opened 1 year ago

dmaljovec commented 1 year ago

Closes https://github.com/nasirhjafri/libyear/issues/33

dmaljovec commented 1 year ago

Caveat, I added no tests, but happy to do so if there is some direction here.

dmaljovec commented 1 year ago

Example usage of the new feature:

$ libyear --help
usage: libyear [-h] [-r R] [--sort] [-f {text,json,csv}]

options:
  -h, --help            show this help message and exit
  -r R                  Requirements file/path
  --sort                Sort by years behind, in descending order
  -f {text,json,csv}, --format {text,json,csv}
                        The output format to use (default: text)
$ libyear -r test_requirements.txt        
+---------+-----------------+----------------+-----------------+
| Library | Current Version | Latest Version | Libyears behind |
+---------+-----------------+----------------+-----------------+
|  pytest |     7.0.0rc1    |     7.4.0      |       1.54      |
+---------+-----------------+----------------+-----------------+
Your system is 1.54 libyears behind
$ libyear -f json -r test_requirements.txt
[
    [
        "Library",
        "Current Version",
        "Latest Version",
        "Libyears behind"
    ],
    {
        "Current Version": "7.0.0rc1",
        "Latest Version": "7.4.0",
        "Library": "pytest",
        "Libyears behind": "1.54"
    }
]
$ libyear --format csv -r test_requirements.txt
Library,Current Version,Latest Version,Libyears behind
pytest,7.0.0rc1,7.4.0,1.54
$ libyear --format yaml -r test_requirements.txt
usage: libyear [-h] [-r R] [--sort] [-f {text,json,csv}]
libyear: error: argument -f/--format: invalid Format value: 'yaml'