2021-02-22 17:38:39 +01:00
|
|
|
package views
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/command/arguments"
|
|
|
|
"github.com/hashicorp/terraform/states"
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
"github.com/hashicorp/terraform/tfdiags"
|
|
|
|
)
|
|
|
|
|
|
|
|
// The Refresh view is used for the refresh command.
|
|
|
|
type Refresh interface {
|
|
|
|
Outputs(outputValues map[string]*states.OutputValue)
|
|
|
|
|
|
|
|
Operation() Operation
|
|
|
|
Hooks() []terraform.Hook
|
|
|
|
|
|
|
|
Diagnostics(diags tfdiags.Diagnostics)
|
2021-02-26 22:31:12 +01:00
|
|
|
HelpPrompt()
|
2021-02-22 17:38:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewRefresh returns an initialized Refresh implementation for the given ViewType.
|
|
|
|
func NewRefresh(vt arguments.ViewType, runningInAutomation bool, view *View) Refresh {
|
|
|
|
switch vt {
|
|
|
|
case arguments.ViewHuman:
|
|
|
|
return &RefreshHuman{
|
2021-02-26 22:31:12 +01:00
|
|
|
view: view,
|
2021-02-22 17:38:39 +01:00
|
|
|
inAutomation: runningInAutomation,
|
|
|
|
countHook: &countHook{},
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
panic(fmt.Sprintf("unknown view type %v", vt))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// The RefreshHuman implementation renders human-readable text logs, suitable for
|
|
|
|
// a scrolling terminal.
|
|
|
|
type RefreshHuman struct {
|
2021-02-26 22:31:12 +01:00
|
|
|
view *View
|
2021-02-22 17:38:39 +01:00
|
|
|
|
|
|
|
inAutomation bool
|
|
|
|
|
|
|
|
countHook *countHook
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ Refresh = (*RefreshHuman)(nil)
|
|
|
|
|
|
|
|
func (v *RefreshHuman) Outputs(outputValues map[string]*states.OutputValue) {
|
|
|
|
if len(outputValues) > 0 {
|
2021-02-26 22:31:12 +01:00
|
|
|
v.view.streams.Print(v.view.colorize.Color("[reset][bold][green]\nOutputs:\n\n"))
|
|
|
|
NewOutput(arguments.ViewHuman, v.view).Output("", outputValues)
|
2021-02-22 17:38:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *RefreshHuman) Operation() Operation {
|
2021-02-26 22:31:12 +01:00
|
|
|
return NewOperation(arguments.ViewHuman, v.inAutomation, v.view)
|
2021-02-22 17:38:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (v *RefreshHuman) Hooks() []terraform.Hook {
|
|
|
|
return []terraform.Hook{
|
|
|
|
v.countHook,
|
2021-02-26 22:31:12 +01:00
|
|
|
NewUiHook(v.view),
|
2021-02-22 17:38:39 +01:00
|
|
|
}
|
|
|
|
}
|
2021-02-26 22:31:12 +01:00
|
|
|
|
|
|
|
func (v *RefreshHuman) Diagnostics(diags tfdiags.Diagnostics) {
|
|
|
|
v.view.Diagnostics(diags)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *RefreshHuman) HelpPrompt() {
|
|
|
|
v.view.HelpPrompt("refresh")
|
|
|
|
}
|