github.com/replicatedhq/ship@v0.55.0/pkg/lifecycle/message/cli.go (about) 1 package message 2 3 import ( 4 "context" 5 "fmt" 6 7 "github.com/go-kit/kit/log" 8 "github.com/go-kit/kit/log/level" 9 "github.com/mitchellh/cli" 10 "github.com/pkg/errors" 11 "github.com/replicatedhq/ship/pkg/api" 12 "github.com/replicatedhq/ship/pkg/lifecycle" 13 "github.com/replicatedhq/ship/pkg/templates" 14 "github.com/spf13/viper" 15 "go.uber.org/dig" 16 ) 17 18 var _ lifecycle.Messenger = &CLIMessenger{} 19 20 type CLIMessenger struct { 21 dig.In 22 23 Logger log.Logger 24 UI cli.Ui 25 Viper *viper.Viper 26 BuilderBuilder *templates.BuilderBuilder 27 } 28 29 func (m *CLIMessenger) Execute(ctx context.Context, release *api.Release, step *api.Message) error { 30 debug := level.Debug(log.With(m.Logger, "step.type", "message")) 31 32 debug.Log("event", "step.execute", "step.level", step.Level) 33 34 builder, err := m.BuilderBuilder.BaseBuilder(release.Metadata) 35 if err != nil { 36 return errors.Wrap(err, "get builder") 37 } 38 39 built, _ := builder.String(step.Contents) 40 41 switch step.Level { 42 case "error": 43 m.UI.Error(fmt.Sprintf("\n%s", built)) 44 case "warn": 45 m.UI.Warn(fmt.Sprintf("\n%s", built)) 46 case "debug": 47 m.UI.Output(fmt.Sprintf("\n%s", built)) 48 default: 49 m.UI.Info(fmt.Sprintf("\n%s", built)) 50 } 51 return nil 52 }