poc: Add JSON output to workspace list in a way that's non-breaking for human output#38159
Closed
SarahFrench wants to merge 20 commits intomainfrom
Closed
poc: Add JSON output to workspace list in a way that's non-breaking for human output#38159SarahFrench wants to merge 20 commits intomainfrom
workspace list in a way that's non-breaking for human output#38159SarahFrench wants to merge 20 commits intomainfrom
Conversation
workspace list in a way that's non-breaking for human output
workspace list in a way that's non-breaking for human outputworkspace list in a way that's non-breaking for human output
5adbd34 to
8e52692
Compare
3 tasks
536526f to
1115d1a
Compare
…th colour enabled or disabled
…or human output. Update how output is returned by the command to use a single List method.
… `arguments` package
…s explaining code.
…ir()` to separate concerns
This was accidentally removed in 450e136
…de a WorkingDir value. This is necessary after the changes in b32b60f
…n via the arguments package
d441800 to
1a44d29
Compare
3 tasks
Member
Author
|
Closing in favour of 2 PRs |
…ion is consistent in the JSON view
1ebe8f2 to
90f3986
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related to #37439
This PR
This PR shows how a command that still uses
cli.Uifor human output could be changed to enable JSON output.These changes include:
1. Making the command process arguments using the arguments package
terraform/internal/command/workspace_list.go
Lines 26 to 33 in 2cf22a7
2. Making the command use a views-like pattern to control how output is sent to streams, but preserving human-readable output being produced via cli.Ui to avoid breaking changes
terraform/internal/command/workspace_list.go
Lines 146 to 150 in 2cf22a7
3. The config path is now obtained like this, to avoid the ModulePath method that makes it hard to add new arguments/flags to arguments (see also #38358):
terraform/internal/command/workspace_list.go
Line 60 in 2cf22a7
4. I refactored the command's
Runmethod to use a single List method on the view to render results and/or diagnostics:Happy path:
terraform/internal/command/workspace_list.go
Line 91 in 2cf22a7
Unhappy path example:
terraform/internal/command/workspace_list.go
Lines 72 to 75 in 2cf22a7
Details
WorkspaceList interface
This PR adds an interface in the views package called WorkspaceList:
terraform/internal/command/views/workspace.go
Lines 18 to 20 in 2cf22a7
When JSON output is produced it uses an implementation of that interface that's in the views package. That implementation uses a View internally.
When human-readable output is produced the WorkspaceList implementation is defined in the command package, because that implementation uses cli.Ui internally. This has to live in the command package as use of cli.Ui is coupled to the Meta.
JSON output is a static log
The new JSON output is a static log. Its top-level structure is the same regardless of outcome, making the JSON easier to consume.
In the happy path, including a warning, output looks like:
{ "workspaces": [ { "name": "default", "is_current": true }, { "name": "dev", "is_current": false }, { "name": "stage", "is_current": false }, { "name": "prod", "is_current": false } ], "diagnostics": [ { "severity": "warning", "summary": "Warning!", "detail": "Consider yourself warned." } ] }In the unhappy path output looks like:
{ "workspaces": [], "diagnostics": [ { "severity": "error", "summary": "Error from test", "detail": "This is a error from the mocked state store." } ] }Target Release
N/A
Rollback Plan
Changes to Security Controls
Are there any changes to security controls (access controls, encryption, logging) in this pull request? If so, explain.
CHANGELOG entry