Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement machine-readable output for commands #867

Closed
3 tasks done
jan-kolarik opened this issue Sep 5, 2023 · 6 comments
Closed
3 tasks done

Implement machine-readable output for commands #867

jan-kolarik opened this issue Sep 5, 2023 · 6 comments
Assignees
Labels
Priority: MEDIUM Triaged Someone on the DNF 5 team has read the issue and determined the next steps to take
Milestone

Comments

@jan-kolarik
Copy link
Member

jan-kolarik commented Sep 5, 2023

Based on the #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:

This issue is targeted for Fedora 41. Other commands to be implemented are scheduled in the follow-up #1906.

@github-project-automation github-project-automation bot moved this to Backlog in DNF team Sep 5, 2023
@softwaresale
Copy link
Contributor

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
Copy link
Member Author

jan-kolarik commented Dec 15, 2023

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 jan-kolarik added Priority: MEDIUM Triaged Someone on the DNF 5 team has read the issue and determined the next steps to take labels Jan 2, 2024
@jan-kolarik jan-kolarik moved this from Backlog to In Progress in DNF team Jan 8, 2024
@jan-kolarik jan-kolarik self-assigned this Jan 8, 2024
@jan-kolarik
Copy link
Member Author

Following-up on #1072 (comment), 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.

@joshcooper
Copy link

Puppet currently relies on the -d 0 -e 1 options when installing dnf packages, which doesn't work under dnf5 puppetlabs/puppet#9506

Having a stable JSON-based output for dnf list, dnf install, etc would be very useful to us.

@jcpunk
Copy link

jcpunk commented Nov 7, 2024

Adding another use case to this, I'd be better able to parse the output of dnf5 with ansible or shell scripts if there was a JSON style output for more detailed host reporting.

For example, parsing the output of updateinfo into something I could drop in /etc/motd.d/ as a sort of preview to needs-restarting for scheduling updates.

@kontura
Copy link
Contributor

kontura commented Nov 8, 2024

For example, parsing the output of updateinfo into something I could drop in /etc/motd.d/ as a sort of preview to needs-restarting for scheduling updates.

I think that dnf updateinfo list --json should already be working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority: MEDIUM Triaged Someone on the DNF 5 team has read the issue and determined the next steps to take
Projects
Archived in project
Development

No branches or pull requests

5 participants