refactor: Change workspace list to use view.View instead of cli.Ui when rendering human output to the terminal#38103
refactor: Change workspace list to use view.View instead of cli.Ui when rendering human output to the terminal#38103SarahFrench wants to merge 4 commits intomainfrom
workspace list to use view.View instead of cli.Ui when rendering human output to the terminal#38103Conversation
…when rendering human output to the terminal
…ct of the -no-color flag
Changelog WarningCurrently this PR would target a v1.15 release. Please add a changelog entry for in the .changes/v1.15 folder, or discuss which release you'd like to target with your reviewer. If you believe this change does not need a changelog entry, please add the 'no-changelog-needed' label. |
workspace list to use view.View instead of cli.Ui when rendering human output to the terminal
| // Warning swaps from stderr to stdout after switching to View from Ui | ||
| // Ui (MockUi)prints warnings to stderr: | ||
| // https://github.com/hashicorp/cli/blob/4383e52914f5677576e148a6d7e1f399c0e91a7c/ui_mock.go#L75-L80 | ||
| // View prints warnings to stdout: | ||
| // https://github.com/hashicorp/terraform/blob/ac3e32b62bdd35dad7cc3e9ad000119fdb537f65/internal/command/views/view.go#L120-L124 |
There was a problem hiding this comment.
To be removed during review, but leaving here for now so it's super obvious where we can see the impact of this change so far
|
Closing this - I have another branch with these types of changes but allow continued use of cli.UI for human output to prevent breaking changes. |
|
I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions. |
Background
Part of #37439
This PR changes just the
workspace listcommand to use the newer view.View abstraction for rendering output. Please see the issue above for more context.The
workspace listcommand only supports human-readable output, before this PR and after this PR. However the changes in this PR make adding support for machine-readable output reasonably easy. I'm planning to do that in future, separately.This PR
This PR introduces structs in the
viewspackage (WorkspaceHuman, etc) to enable rendering diagnostics and text notices to the terminal. Diagnostics can be received from backends/state stores when retrieving the list of workspaces via theirWorkspacesmethods or could be raised in the command itself (#38094). The text notices include the list output of the command itself:Those structs are then used in the
workspace selectcommand. E.g. instead ofc.Ui.Errorto log errors, the code uses the genericview.Diagnosticsmethod to render diagnostics (both warning or error level).Things for the reviewer to note
There is a change in behaviour when rendering warning diagnostics.
When using cli.Ui, warnings are logged to stderr:
when using view.View's
Diagnosticsmethod, warnings are logged to stdout:terraform/internal/command/views/view.go
Lines 120 to 124 in ac3e32b
I'm still trying to work out if we consider this a breaking change or not, but I'm leaning towards not:
The only issue I've found so far is that the parsing of human output in terraform-exec relies on stdout containing only the list of workspaces. I've got a proposed change to fix this in: hashicorp/terraform-exec#562
However the best route forward would be to add machine-readable output support to the
workspacecommands and update terraform-exec to use that instead.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