1package views 2 3import ( 4 "fmt" 5 6 "github.com/hashicorp/terraform/internal/command/arguments" 7) 8 9// The StateLocker view is used to display locking/unlocking status messages 10// if the state lock process takes longer than expected. 11type StateLocker interface { 12 Locking() 13 Unlocking() 14} 15 16// NewStateLocker returns an initialized StateLocker implementation for the given ViewType. 17func NewStateLocker(vt arguments.ViewType, view *View) StateLocker { 18 switch vt { 19 case arguments.ViewHuman: 20 return &StateLockerHuman{view: view} 21 default: 22 panic(fmt.Sprintf("unknown view type %v", vt)) 23 } 24} 25 26// StateLockerHuman is an implementation of StateLocker which prints status to 27// a terminal. 28type StateLockerHuman struct { 29 view *View 30} 31 32var _ StateLocker = (*StateLockerHuman)(nil) 33 34func (v *StateLockerHuman) Locking() { 35 v.view.streams.Println("Acquiring state lock. This may take a few moments...") 36} 37 38func (v *StateLockerHuman) Unlocking() { 39 v.view.streams.Println("Releasing state lock. This may take a few moments...") 40} 41