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

feat: init and get command support json format output #1453

Merged

Conversation

Ericwww
Copy link
Contributor

@Ericwww Ericwww commented Apr 1, 2024

Resolves #1373

In init or get package, lots of output is calling method on cli.UI interface

If 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.)

image

I create a wrappedUI and implement the cli.UI interface. It contains jsonView and cli.UI in it.

If -json is given, wrappedUI will call the method on jsonView. If not, wrappedUI will call the method on cli.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.

image

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

{"@level":"info","@message":"- Finding hashicorp/tfcoremock versions matching \"\u003e=0.1.2\"...","@module":"tofu.ui","@timestamp":"2024-04-01T15:48:41.198485+02:00"}

Target Release

1.7.0

Copy link

github-actions bot commented Apr 1, 2024

Reminder for the PR assignee: If this is a user-visible change, please update the changelog as part of the PR.

@Ericwww Ericwww force-pushed the checks-workflow-dev/init-support-json branch 2 times, most recently from 9542974 to 2aa807c Compare April 1, 2024 15:53
@Ericwww Ericwww marked this pull request as ready for review April 1, 2024 15:58
@Ericwww Ericwww requested a review from a team as a code owner April 1, 2024 15:58
cam72cam
cam72cam previously approved these changes Apr 1, 2024
Copy link
Contributor

@cam72cam cam72cam left a 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 👍

Signed-off-by: Syasusu <syasusu@163.com>
Signed-off-by: Syasusu <syasusu@163.com>
Signed-off-by: Syasusu <syasusu@163.com>
@Ericwww Ericwww force-pushed the checks-workflow-dev/init-support-json branch from 69f0cee to 7ec2a79 Compare April 1, 2024 18:36
@Ericwww Ericwww changed the title init and get command support json format output feat: init and get command support json format output Apr 1, 2024
cam72cam
cam72cam previously approved these changes Apr 1, 2024
@Ericwww
Copy link
Contributor Author

Ericwww commented Apr 1, 2024

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

{"@level":"info","@message":"- Finding hashicorp/tfcoremock versions matching \"\u003e=0.1.2\"...","@module":"tofu.ui","@timestamp":"2024-04-01T15:48:41.198485+02:00"}

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>
@cam72cam cam72cam merged commit bdab869 into opentofu:main Apr 2, 2024
8 checks passed
hrboyceiii pushed a commit to thedotworks/opentofu that referenced this pull request Apr 6, 2024
bunniseng pushed a commit to bunniseng/opentofu that referenced this pull request Apr 8, 2024
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.

Add -json flag for tofu init to support output json format diagnostic
3 participants