-
Notifications
You must be signed in to change notification settings - Fork 989
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
proposing new --format=<format> --out-file=<file.ext> feature #17507
base: develop2
Are you sure you want to change the base?
Conversation
Related to #17462 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question, otherwise looks good, but I think checking with the team in as look-into is a good idea first, good call
conan/api/output.py
Outdated
""" | ||
Output to be used by formatters to dump information to stdout | ||
""" | ||
if filename is not None: | ||
ConanOutput().info(f"Formatted output saved to '{filename}'") | ||
save(filename, data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a few commands whose formatter calls cli_out_write
multiple times in a row.
Should we convert those to only call it once, or should this new functionality support appending?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. Not sure to be honest, I tend to think to re-write the formatter to include only 1 call, but there are some case that use colors and that would be a bit less elegant, but still doable
I'm not sure I prefer this over having a new |
Yes, I like that midpoint. I thought about the extra argument, but that further pollutes the CLI, like But if you think the --output-file is better, we can do it too, I am not strongly opposed either. |
The main thing for me is to maintain the concept of a formatter. A |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good
conan/cli/commands/graph.py
Outdated
@@ -192,6 +192,9 @@ def graph_info(conan_api, parser, subparser, *args): | |||
help="Deployer output folder, base build folder by default if not set") | |||
subparser.add_argument("--build-require", action='store_true', default=False, | |||
help='Whether the provided reference is a build-require') | |||
subparser.add_argument("--out-file", action=OnceArgument, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be injected automatically and conditionally to the existence of formatters together with the definition of the --format
argument. There cannot be a --out-file
without a --format
definition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finally, my proposal is to add the --out-file
always, to enable users do for example
conan config home --out-file=file.ext
and it uses the text formatter that is the one by default. Because in the end, there's always a formatter there that is the text
one even if it does not show in the --help
, but let's discuss about this with the team.
EDIT: Looks like this works in the test suite but not in my CLI, I'm leaving the PR in draft until I understand why.
I'm leaving this as draft, apparently these lines: Lines 298 to 300 in 003e2cf
are making that this approach redirecting the stdout do not work on a real console but they do work on testing because we capture the streams. I'll investigate a solution that also prevent #17245 to not happen any more. |
Changelog: Feature: Allow defining
--out-file=file.ext
instead of--format=ext > file.ext
to write to files directly and avoid issues with redirects.Docs: https://github.com/conan-io/docs/pull/XXXX
This would solve issues with stdout/stderr redirects and potential pollution, while not using new arguments, not breaking existing code and allow easy introduction to existing formatters.
Close #17462