ui_concurrent.go 877 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package cli
  2. import (
  3. "sync"
  4. )
  5. // ConcurrentUi is a wrapper around a Ui interface (and implements that
  6. // interface) making the underlying Ui concurrency safe.
  7. type ConcurrentUi struct {
  8. Ui Ui
  9. l sync.Mutex
  10. }
  11. func (u *ConcurrentUi) Ask(query string) (string, error) {
  12. u.l.Lock()
  13. defer u.l.Unlock()
  14. return u.Ui.Ask(query)
  15. }
  16. func (u *ConcurrentUi) AskSecret(query string) (string, error) {
  17. u.l.Lock()
  18. defer u.l.Unlock()
  19. return u.Ui.AskSecret(query)
  20. }
  21. func (u *ConcurrentUi) Error(message string) {
  22. u.l.Lock()
  23. defer u.l.Unlock()
  24. u.Ui.Error(message)
  25. }
  26. func (u *ConcurrentUi) Info(message string) {
  27. u.l.Lock()
  28. defer u.l.Unlock()
  29. u.Ui.Info(message)
  30. }
  31. func (u *ConcurrentUi) Output(message string) {
  32. u.l.Lock()
  33. defer u.l.Unlock()
  34. u.Ui.Output(message)
  35. }
  36. func (u *ConcurrentUi) Warn(message string) {
  37. u.l.Lock()
  38. defer u.l.Unlock()
  39. u.Ui.Warn(message)
  40. }