rpm-software-management / dnf5

Next-generation RPM package management system
Other
221 stars 74 forks source link

Implement machine-readable output for commands #867

Open jan-kolarik opened 10 months ago

jan-kolarik commented 10 months ago

Based on the https://github.com/rpm-software-management/dnf5/issues/512, the target format for machine-readable output should be json, which is also supported by the libsmartcols library, commonly used for command output in DNF.

For the supported commands, machine-readable output will be requested with the --json option.

Commands to be implemented:

softwaresale commented 9 months ago

It looks like there is a JSON wrapper in copr already. Would it be worth while to either:

  1. Move that wrapper into libdnf5 so that it can be used across the different commands
  2. Create a new wrapper in libdnf5 instead of reusing copr's
  3. Not create a wrapper at all and just use raw json-c
jan-kolarik commented 7 months ago

It looks like there is a JSON wrapper in copr already. Would it be worth while to either:

  1. Move that wrapper into libdnf5 so that it can be used across the different commands
  2. Create a new wrapper in libdnf5 instead of reusing copr's
  3. Not create a wrapper at all and just use raw json-c

Hi, thanks for the suggestion. I was looking into the copr plugin and there it is really used for processing the JSON input. Here for the machine-readable output we would probably just utilize the libsmartcols functionality to print the output in JSON format and probably do some transformation of the existing scols table into the json scols one. So it looks to me so far that no JSON library would be needed for this use case.

jan-kolarik commented 6 months ago

Following-up on https://github.com/rpm-software-management/dnf5/issues/1072#issuecomment-1887165817, I was trying to utilize the libsmartcols API for JSON outputs. Unfortunately, I couldn't find a way to produce nested JSON objects. Even without that, the code became cumbersome when trying to transpose the existing tables for a more natural JSON output.

I'll proceed by attempting to utilize the existing json-c library for this, taking into account the common JSON wrapper in libdnf5, as suggested by @softwaresale if it makes sense. However, the refactoring of the output header files is necessary first. Therefore I'm postponing the work until the related issue is resolved.