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

[bug][2.0] conan config list prints to stderr #12200

Closed
fschoenm opened this issue Sep 26, 2022 · 8 comments
Closed

[bug][2.0] conan config list prints to stderr #12200

fschoenm opened this issue Sep 26, 2022 · 8 comments
Labels
Milestone

Comments

@fschoenm
Copy link

Environment Details (include every applicable attribute)

  • Operating System+version: Ubuntu 22.04
  • Compiler+version:
  • Conan version: 2.0.0-beta3
  • Python version:

Steps to reproduce (Include if Applicable)

conan config list prints all available config options to stderr instead of stdout. That makes it difficult/annoying to e.g. grep for options.

Logs (Executed commands with output) (Include/Attach if Applicable)

@memsharded
Copy link
Member

It is because it has a dedicated --format=json output that goes to stdout. We cannot make the normal text output go to stdout otherwise it will break --format=json > file.json to capture a clean json output.

The alternatives are:

  • We add a --format=text output, the prints the text format to stdout when defined
  • We drop the --format=json output, agree that it will not be a thing in the future, and send the output by default to stdout

@fschoenm
Copy link
Author

I guess I don't understand why the command has to print both, text and JSON at the same time. Isn't that an either/or thing? I don't even know what I would do with the JSON output of this command.

However, the current behavior breaks all kinds of expectations how command line interfaces should behave and that's why I opened the ticket.

We cannot make the normal text output go to stdout otherwise it will break --format=json > file.json to capture a clean json output.

You could make the same argument about redirecting non-JSON text output.

@memsharded
Copy link
Member

The way the Conan 2.0 cli output is designed is this:

  • Only "end-results", machine readable, maybe concatenable output to other commands goes to stdout. This should be pretty stable
  • All informational messages to be read by humans go to stderr. They are not stable in the contents, the format, the layout, the coloring, can change at any release. Users should not parse or use such output for anything rather than human reading them
  • Commands have --format=xxxx formatters to output json, html or whatever other format they support. They will go to stdout and are intended for automation and as such should be stable

Now, the command at hand conan config list, got a --format=json, because someone thought that some users might want a stable json output of all the built-in confs. Such json format output will go to stdout and will be considered stable.
We don't want users parsing the normal text output, because if we decided to change its format, for example groups commands, add some tabs by group, or whatever other change, will break their parsing and break their automation/CI/pipelines.

I'll check with the team to re-consider this use case of grepping.

@memsharded memsharded added this to the 2.0.0-beta4 milestone Sep 28, 2022
@fschoenm
Copy link
Author

Ok. To me that seems like a pretty uncommon guideline for CLI programs that I've not seen before. IMO most output will still be read by humans and might get grepped, piped to less, or redirected to log files. The conventions you decided on for Conan 2.0 seem to break all that without a very good reason.

How are you going to handle this? Does the end user always have to remember to redirect stderr to stdout or it just doesn't behave as expected?

Of course I get the need for having stable, machine-readable output but that can be explicitly requested with e.g. the --format parameter. I just don't understand this hard distinction or why it would be so useful to have human-readable and JSON output at the same time or why the guidelines have to be so rigid to break normal CLI behavior.

(Another example of this kind of irritating CLI behavior is calling conan config list --help. Instead of just showing the help for that command as expected it also prints the conan config list output without being asked to (and again to stderr).)

@memsharded
Copy link
Member

This will be changed, @czoido is working on it for next beta.4

@lindblandro
Copy link

Just bumped into this and would also like to point out that the output of conan config list is essentially the same as the json output, with the exception that the text output contains Supported Conan global.conf and [conf] properties: which I think should go to conan config list --help. After you've run that command once you know what it does and you don't need the manual to be printed every time. Imagine if git config --list would begin it's listing with Current git configuration settings: or something.

I'd say the most intuitive way would be to keep the default listing 1-to-1 with other stable formats and add additional flags to make it look nicer. Again with the git examples: git log vs git log --oneline --graph. The current output is pretty readable as it is, but if you want to support easier grouping, add an optional globbing pattern: conan config list core.* and so on, but please don't make the customized special case output the default.

@memsharded
Copy link
Member

Fixed by #12235, will be in next beta.4

@memsharded
Copy link
Member

@lindblandro

I agree, those explanations can be removed. We have fixed it in #12235, removing those things too, but if there are still some pending or a new one appears, please submit a new issue, or create a PR to remove it. Thanks!

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

No branches or pull requests

3 participants