-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Workload commands: JSON only output adjustments #35640
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
Conversation
…ing JSON only output to only output JSON. This removed the starting/ending tags and any potential output of called functionality. It pipes a NullReporter into the necessary components.
…ing passed through the constructor chain, which is needed for unit testing. Adjusted failing unit tests based on changes.
Added When you commit this breaking change:
Tagging @dotnet/compat for awareness of the breaking change. |
Can you explain why you had to pass in the null reporter as opposed to just removing more instances of |
The lines written by those other classes are used by all the other commands that don't feature the flags that print out JSON. So, the commands (
The main issue is just a result of the class hierarchy and construction. Also, the combination of the "good path" constructor (path the code normally takes when running) with the "unit test" constructor makes it a bit convoluted in how to solve this without breaking tests. Most designs have these as 2 separate constructors. Adding a Boolean doesn't buy us much, other than adding boilerplate code around every |
Thanks for the explanation! So I guess the only case in which we'd have to roll back part of this change would be if we decided to add text to one of those subcommands...which seems unlikely. On the global boolean idea, it might be interesting to have an optional argument on WriteLine that, if false (default: true), would only write the line if the global boolean is true. I do think that would be a nice, clean structure and very forward-compatible, but I think it's fine to skip it for now since you said it isn't a priority 🙂 |
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.
Looks good to me! I was thinking about proposing either unifying the new NuGetPackageDownloader calls in one place, but I don't think that's really worth it. You can't just do it in place of the boolean unless you want it for commands that don't need it, which would be wasteful.
Breaking change issue for dotnet/docs created here: dotnet/docs#37278 |
Fixes: #22887
Note
This PR is a breaking change.
I do plan to also work on this issue which would be good to lump together in the same breaking change doc.
Summary
There were a couple of primary changes:
Commands adjusted:
dotnet workload list --machine-readable
dotnet workload install --print-download-link-only
dotnet workload update --print-download-link-only
dotnet workload update --print-rollback
Details
The first change (boundary lines) was very simple and just involved removing a couple of
WriteLine
outputs for each command. Then, adjusting tests accordingly.The second change was a bit more involved. We use a
Reporter
to write out to the console. Think of it as just an output stream. Right now, these commands are designed to:Reporter
down through the workload command hierarchy.Reporter.Output
will be used.Reporter
property can only be set via this constructor hierarchy.For the commands in question, we need to:
Reporter
to write the JSON appropriatelyReporter
beyond writing the JSON is replaced withNullReporter.Instance
To do this was a bit tricky. I had to add the ability to pass a
Reporter
to several methods that utilized it. But there was something else that also needed adjusted. ThePackageDownloader
is also created deep in the hierarchy using theReporter
from the constructor. Since I actually want to utilize theReporter
being passed in to write the JSON, I can't just force theReporter
property to beNullReporter
.So, I ended up creating a new instance of
NuGetPackageDownloader
for this situation. It also allowed me to use aNullLogger
which applies to the NuGet messages. For unit testing, I had to addIsPackageDownloaderProvided
to indicate that aPackageDownloader
was passed through the constructor hierarchy. Then, I use thatPackageDownloader
instead of creating a new one.