kellyjonbrazil / jc

CLI tool and python library that converts the output of popular command-line tools, file-types, and common strings to JSON, YAML, or Dictionaries. This allows piping of output to tools like jq and simplifying automation scripts.
MIT License
7.69k stars 195 forks source link

New parser request: pacman -Si #570

Open brainwo opened 1 month ago

brainwo commented 1 month ago

I'm not sure if there is already parser that can help with this. Here is an example of pacman -Si output:

Repository      : extra
Name            : jc
Version         : 1.25.2-1
Description     : Converts the output of popular command-line tools and file-types
                  to JSON
Architecture    : any
URL             : https://github.com/kellyjonbrazil/jc
Licenses        : MIT
Groups          : None
Provides        : None
Depends On      : python  python-pygments  python-ruamel-yaml  python-xmltodict
Optional Deps   : None
Conflicts With  : None
Replaces        : None
Download Size   : 866.14 KiB
Installed Size  : 8474.19 KiB
Packager        : Antonio Rojas <arojas@archlinux.org>
Build Date      : Mon 06 May 2024 02:37:45 PM +08
Validated By    : SHA-256 Sum  Signature
kellyjonbrazil commented 1 month ago

Hi there - it looks like two parsers that can work for this output would be the --kv parser or the --rpm-qi parser, which is also used for various other package index parsers, like --pkg-index-deb.

I can create a parser specifically for this format if these parsers don't work for specific output. I can probably modify the --rpm-qi parser and create a new alias for pacman -Si output.

$ echo 'Repository      : extra                       
Name            : jc
Version         : 1.25.2-1
Description     : Converts the output of popular command-line tools and file-types
                  to JSON
Architecture    : any
URL             : https://github.com/kellyjonbrazil/jc
Licenses        : MIT
Groups          : None
Provides        : None
Depends On      : python  python-pygments  python-ruamel-yaml  python-xmltodict
Optional Deps   : None
Conflicts With  : None
Replaces        : None
Download Size   : 866.14 KiB
Installed Size  : 8474.19 KiB
Packager        : Antonio Rojas <arojas@archlinux.org>
Build Date      : Mon 06 May 2024 02:37:45 PM +08
Validated By    : SHA-256 Sum  Signature' | jc --kv -p           
{
  "Repository": "extra",
  "Name": "jc",
  "Version": "1.25.2-1",
  "Description": "Converts the output of popular command-line tools and file-types\nto JSON",
  "Architecture": "any",
  "URL": "https://github.com/kellyjonbrazil/jc",
  "Licenses": "MIT",
  "Groups": "None",
  "Provides": "None",
  "Depends On": "python  python-pygments  python-ruamel-yaml  python-xmltodict",
  "Optional Deps": "None",
  "Conflicts With": "None",
  "Replaces": "None",
  "Download Size": "866.14 KiB",
  "Installed Size": "8474.19 KiB",
  "Packager": "Antonio Rojas <arojas@archlinux.org>",
  "Build Date": "Mon 06 May 2024 02:37:45 PM +08",
  "Validated By": "SHA-256 Sum  Signature"
}

$ echo 'Repository      : extra
Name            : jc
Version         : 1.25.2-1
Description     : Converts the output of popular command-line tools and file-types
                  to JSON
Architecture    : any
URL             : https://github.com/kellyjonbrazil/jc
Licenses        : MIT
Groups          : None
Provides        : None
Depends On      : python  python-pygments  python-ruamel-yaml  python-xmltodict
Optional Deps   : None
Conflicts With  : None
Replaces        : None
Download Size   : 866.14 KiB
Installed Size  : 8474.19 KiB
Packager        : Antonio Rojas <arojas@archlinux.org>
Build Date      : Mon 06 May 2024 02:37:45 PM +08
Validated By    : SHA-256 Sum  Signature' | jc --rpm-qi -p
[
  {
    "repository": "extra"
  },
  {
    "name": "jc",
    "version": "1.25.2-1",
    "description": "Converts the output of popular command-line tools and file-types",
    "architecture": "any",
    "url": "https://github.com/kellyjonbrazil/jc",
    "licenses": "MIT",
    "groups": "None",
    "provides": "None",
    "depends_on": "python  python-pygments  python-ruamel-yaml  python-xmltodict",
    "optional_deps": "None",
    "conflicts_with": "None",
    "replaces": [
      "None"
    ],
    "download_size": "866.14 KiB",
    "installed_size": 8474,
    "packager": "Antonio Rojas <arojas@archlinux.org>",
    "build_date": "Mon 06 May 2024 02:37:45 PM +08",
    "validated_by": "SHA-256 Sum  Signature",
    "build_epoch": null,
    "build_epoch_utc": null
  }
]
brainwo commented 1 month ago

A new parser would be nice. I see there are inconsistency on the use of null and "None", as well as "depends_on" values not being an array. And that "\n" inside the string too.

Also I want to mention there is this flag -Qi that does output the same as -Si, but it's for querying installed package. -Q is short hand for --query, and -S is for --sync while -i is for --info. (If this information matters. Perhaps for naming the command or for jc magic?)

Another thing is I got a question: If I got some new format I don't know what parser to use, how can I find what to use? Is there a list of how other formats looks like? I'm not familiar with how other format works, like other package managers for example (that surely isn't available in my distro of choice).