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

Make output less vebose in --quiet mode #2001

Closed
wants to merge 3 commits into from

Conversation

abitrolly
Copy link

@abitrolly abitrolly commented Jan 12, 2025

Makes --quiet option description more quiet.

Suppress header in dnf list --upgrades and similar one table command.

Closes #753.

@abitrolly abitrolly marked this pull request as ready for review January 12, 2025 18:17
@kontura
Copy link
Contributor

kontura commented Jan 22, 2025

This is really not the right approach, the sections also print the packages. With your patch it doesn't print anything at all when used with -q.

This also didn't work in old dnf.

Can I ask why do you want to hide the headers?

@kontura kontura added the blocked Further work on issue or PR is blocked by something else label Jan 22, 2025
@kontura kontura self-assigned this Jan 22, 2025
@abitrolly
Copy link
Author

Can I ask why do you want to hide the headers?

@kontura I needed to get a list of updates and their versions and these headers were in the way https://gitlab.com/abitrolly/dnf-go-gui/-/blob/master/docs/DNF-API.md

Proper machine readable export, like CSV or JSON will remote the need.

This is really not the right approach, the sections also print the packages. With your patch it doesn't print anything at all when used with -q.

That's unfortunate. I also don't see that patching core lib to handle different verbosity levels is the right thing.

@kontura
Copy link
Contributor

kontura commented Jan 22, 2025

That's unfortunate. I also don't see that patching core lib to handle different verbosity levels is the right thing.

Right, actually we have two libraries: libdnf5 which is for the core functionality and then libdnf5-cli which we use to share command line functionality, formatting and such between tools.

Proper machine readable export, like CSV or JSON will remote the need.

The list command is not intended to be parsed.
Try repoquery:

dnf5 repoquery --upgrades --queryformat="%{name}, %{evr}, %{arch}, %{repoid}\n"

Note that old dnf4 used to add the new line at the end automatically so you might have to check that if you want to use it also with dnf4.

I should also mention that in some situations the output of repoquery or list with --upgrades might differ from the actual transaction of the upgrade command. This is because they don't take obsoletes into account and they don't resolve dependencies they just check which packages have upgrades available.
If you want the packages that will be upgraded by upgrade command you should use check-upgrade command. Unfortunately it doesn't have a proper --json flag for machine readable output yet, but I think it should have it in the future.

Edit: I see you already know this, I should have read your document fully before.

@abitrolly
Copy link
Author

@kontura I think I fixed the quiet flag for now.

If check-upgrade could construct plain 2D table with all fields in text form to be ready to be exported to CSV, maybe I could patch it..

@kontura kontura removed the blocked Further work on issue or PR is blocked by something else label Jan 23, 2025
@kontura
Copy link
Contributor

kontura commented Jan 23, 2025

I am sorry I should have been more clear yesterday but I don't like these changes.

While it is true that dnf5 lacks the machine readable output for most commands in this situation you should use the repoquery command mentioned. It provides the same information and can be formatted exactly as you need.

We don't want to encourage users to parse the list commands.

Perhaps I can keep this open for a while to see if other developers have a different opinion but personally I would close it.

@abitrolly
Copy link
Author

@kontura that's just an example how to make quiet work again #570

I am sorry I should have been more clear yesterday but I don't like these changes.

You don't like how people use the output, or there are technical issues with making --quiet work here?

@ppisar
Copy link
Contributor

ppisar commented Jan 23, 2025

I agree with kontura: Text user interface is not a machine interface. Imposing that onus on the human output would make difficult to evolve it. Also human interface lacks many guarantees API has: Delimiting records, escaping, data types, data structures, versioning, locale independence etc. In short, it's unreasonable to handle a user interface as a machine interface. Both from DNF users and from DNF developers.

Ideally this should be handled by D-Bus interface.

@abitrolly
Copy link
Author

Well, maybe the feature is excessive, but does it work at least? Can other people use the PR as an example how to control output verbosity?

Realistically dnf list maybe useful for simple cut scripts. For Go I'd rather access DB directly. For programmatic API for dnf5 I would take a look at https://www.nushell.sh/ handles data.

@kontura
Copy link
Contributor

kontura commented Jan 24, 2025

Well, maybe the feature is excessive, but does it work at least? Can other people use the PR as an example how to control output verbosity?

Yes, it works. I don't think there are any technical issue with your approach.

In my opinion for your use case it would be best to use the API directly via GO bindings.
Unfortunately they are not working now and we don't have the resources to fix them up. It would require some proficiency with GO and SWIG.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Suppress header in dnf list --upgrades in --quiet mode
3 participants