github.com/opentofu/opentofu@v1.7.1/internal/command/meta_ui.go (about) 1 package command 2 3 import ( 4 "github.com/mitchellh/cli" 5 6 "github.com/opentofu/opentofu/internal/command/views" 7 ) 8 9 // WrappedUi is a shim which adds json compatibility to those commands which 10 // have not yet been refactored to support output by views.View. 11 // 12 // For those not support json output command, all output is printed by cli.Ui. 13 // So we create WrappedUi, contains the old cli.Ui and views.JSONView, 14 // implement cli.Ui interface, so that we can make all command support json 15 // output in a short time. 16 type WrappedUi struct { 17 cliUi cli.Ui 18 jsonView *views.JSONView 19 outputInJSON bool 20 } 21 22 func (m *WrappedUi) Ask(s string) (string, error) { 23 return m.cliUi.Ask(s) 24 } 25 26 func (m *WrappedUi) AskSecret(s string) (string, error) { 27 return m.cliUi.AskSecret(s) 28 } 29 30 func (m *WrappedUi) Output(s string) { 31 if m.outputInJSON { 32 m.jsonView.Output(s) 33 return 34 } 35 m.cliUi.Output(s) 36 } 37 38 func (m *WrappedUi) Info(s string) { 39 if m.outputInJSON { 40 m.jsonView.Info(s) 41 return 42 } 43 m.cliUi.Info(s) 44 } 45 46 func (m *WrappedUi) Error(s string) { 47 if m.outputInJSON { 48 m.jsonView.Error(s) 49 return 50 } 51 m.cliUi.Error(s) 52 } 53 54 func (m *WrappedUi) Warn(s string) { 55 if m.outputInJSON { 56 m.jsonView.Warn(s) 57 return 58 } 59 m.cliUi.Warn(s) 60 }