-
Notifications
You must be signed in to change notification settings - Fork 779
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
feat: init and get command support json format output #1453
feat: init and get command support json format output #1453
Conversation
Reminder for the PR assignee: If this is a user-visible change, please update the changelog as part of the PR. |
9542974
to
2aa807c
Compare
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.
Other than some additional comments, this looks good to me 👍
5476fd1
to
69f0cee
Compare
Signed-off-by: Syasusu <syasusu@163.com>
Signed-off-by: Syasusu <syasusu@163.com>
Signed-off-by: Syasusu <syasusu@163.com>
69f0cee
to
7ec2a79
Compare
Well, hashicorp merged my PR and release a new version. I will fix the problem I mentioned above. It seems OK now. {"@level":"info","@message":"- Finding hashicorp/tfcoremock versions matching \">=0.1.2\"...","@module":"tofu.ui","@timestamp":"2024-04-01T23:59:52.383038+02:00"} |
Signed-off-by: Syasusu <syasusu@163.com>
Signed-off-by: Syasusu <syasusu@163.com>
Signed-off-by: Syasusu <syasusu@163.com>
Resolves #1373
In init or get package, lots of output is calling method on
cli.UI
interfaceIf you want to output in JSON, you should call method on views.JSONView.
I tried to draw a figure to explain the logical here. (the green color is some logical I added in this PR.)
I create a
wrappedUI
and implement thecli.UI
interface. It contains jsonView and cli.UI in it.If
-json
is given,wrappedUI
will call the method onjsonView
. If not,wrappedUI
will call the method oncli.Ui
, be consistent with current logical.Read Before Review
At present, the logic of -json is simply implemented. If you look carefully, there are actually a lot of details that could be better.
For example, in output like the following, characters like
\n
should not appear in theory.But in order to ensure that the previous display information is not changed too much, I can only accept this situation for the time being.
If you have any objections to this, you are welcome to raise it and I will find a way to continue to solve it.
In addition, I also found an issue from hashicorp/go-hclog.
When the information to be output contains some special characters, such as
&
,>
,<
and other symbols, the output will be escaped.I have submitted issues and PRs to this repository, but have not received any feedback yet.
hashicorp/go-hclog#140
Target Release
1.7.0