mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
command: concurrent UI
This commit is contained in:
parent
23de2fc2f3
commit
d3f2547f86
@ -2,6 +2,7 @@ package command
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
"github.com/mitchellh/cli"
|
"github.com/mitchellh/cli"
|
||||||
@ -11,16 +12,29 @@ type UiHook struct {
|
|||||||
terraform.NilHook
|
terraform.NilHook
|
||||||
|
|
||||||
Ui cli.Ui
|
Ui cli.Ui
|
||||||
|
|
||||||
|
once sync.Once
|
||||||
|
ui cli.Ui
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *UiHook) PreDiff(
|
func (h *UiHook) PreDiff(
|
||||||
id string, s *terraform.ResourceState) (terraform.HookAction, error) {
|
id string, s *terraform.ResourceState) (terraform.HookAction, error) {
|
||||||
h.Ui.Output(fmt.Sprintf("Calculating diff for %s", id))
|
h.once.Do(h.init)
|
||||||
|
|
||||||
|
h.ui.Output(fmt.Sprintf("%s: Calculating diff", id))
|
||||||
return terraform.HookActionContinue, nil
|
return terraform.HookActionContinue, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *UiHook) PreRefresh(
|
func (h *UiHook) PreRefresh(
|
||||||
id string, s *terraform.ResourceState) (terraform.HookAction, error) {
|
id string, s *terraform.ResourceState) (terraform.HookAction, error) {
|
||||||
h.Ui.Output(fmt.Sprintf("Refreshing state for %s (ID: %s)", id, s.ID))
|
h.once.Do(h.init)
|
||||||
|
|
||||||
|
h.ui.Output(fmt.Sprintf("%s: Refreshing state (ID: %s)", id, s.ID))
|
||||||
return terraform.HookActionContinue, nil
|
return terraform.HookActionContinue, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *UiHook) init() {
|
||||||
|
// Wrap the ui so that it is safe for concurrency regardless of the
|
||||||
|
// underlying reader/writer that is in place.
|
||||||
|
h.ui = &cli.ConcurrentUi{Ui: h.Ui}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user