github.com/hugorut/terraform@v1.1.3/src/command/views/state_locker.go (about) 1 package views 2 3 import ( 4 "fmt" 5 6 "github.com/hugorut/terraform/src/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. 11 type StateLocker interface { 12 Locking() 13 Unlocking() 14 } 15 16 // NewStateLocker returns an initialized StateLocker implementation for the given ViewType. 17 func 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. 28 type StateLockerHuman struct { 29 view *View 30 } 31 32 var _ StateLocker = (*StateLockerHuman)(nil) 33 34 func (v *StateLockerHuman) Locking() { 35 v.view.streams.Println("Acquiring state lock. This may take a few moments...") 36 } 37 38 func (v *StateLockerHuman) Unlocking() { 39 v.view.streams.Println("Releasing state lock. This may take a few moments...") 40 }