command/views: main View type aware if it's running in automation
This "running in automation" idea is a best effort thing where we try to avoid printing out specific suggestions of commands to run in the main workflow when the user is running Terraform inside a wrapper script or other automation, because they probably don't want to bypass that automation. This just makes that information available to the main views.View type, so we can then make use of it in the implementation of more specialized view types that embed views.View. However, nothing is using it as of this commit. We'll use it in later commits.
This commit is contained in:
parent
6f68065326
commit
bf396b5f1b
|
@ -17,6 +17,13 @@ type View struct {
|
|||
|
||||
compactWarnings bool
|
||||
|
||||
// When this is true it's a hint that Terraform is being run indirectly
|
||||
// via a wrapper script or other automation and so we may wish to replace
|
||||
// direct examples of commands to run with more conceptual directions.
|
||||
// However, we only do this on a best-effort basis, typically prioritizing
|
||||
// the messages that users are most likely to see.
|
||||
runningInAutomation bool
|
||||
|
||||
// This unfortunate wart is required to enable rendering of diagnostics which
|
||||
// have associated source code in the configuration. This function pointer
|
||||
// will be dereferenced as late as possible when rendering diagnostics in
|
||||
|
@ -38,6 +45,18 @@ func NewView(streams *terminal.Streams) *View {
|
|||
}
|
||||
}
|
||||
|
||||
// SetRunningInAutomation modifies the view's "running in automation" flag,
|
||||
// which causes some slight adjustments to certain messages that would normally
|
||||
// suggest specific Terraform commands to run, to make more conceptual gestures
|
||||
// instead for situations where the user isn't running Terraform directly.
|
||||
//
|
||||
// For convenient use during initialization (in conjunction with NewView),
|
||||
// SetRunningInAutomation returns the reciever after modifying it.
|
||||
func (v *View) SetRunningInAutomation(new bool) *View {
|
||||
v.runningInAutomation = new
|
||||
return v
|
||||
}
|
||||
|
||||
// Configure applies the global view configuration flags.
|
||||
func (v *View) Configure(view *arguments.View) {
|
||||
v.colorize.Disable = view.NoColor
|
||||
|
|
|
@ -82,7 +82,7 @@ func initCommands(
|
|||
meta := command.Meta{
|
||||
OriginalWorkingDir: originalWorkingDir,
|
||||
Streams: streams,
|
||||
View: views.NewView(streams),
|
||||
View: views.NewView(streams).SetRunningInAutomation(inAutomation),
|
||||
|
||||
Color: true,
|
||||
GlobalPluginDirs: globalPluginDirs(),
|
||||
|
|
Loading…
Reference in New Issue