diff --git a/cmd/provision/server.go b/cmd/provision/server.go index 14eea84..9822bf4 100644 --- a/cmd/provision/server.go +++ b/cmd/provision/server.go @@ -14,6 +14,7 @@ import ( tracifyprovider "github.com/foomo/sesamy-cli/pkg/provider/tracify" umamiprovider "github.com/foomo/sesamy-cli/pkg/provider/umami" "github.com/foomo/sesamy-cli/pkg/tagmanager" + "github.com/foomo/sesamy-cli/pkg/utils" "github.com/pkg/errors" "github.com/pterm/pterm" "github.com/spf13/cobra" @@ -143,7 +144,8 @@ func NewServer(root *cobra.Command) { } tree.Children = append(tree.Children, child) } - if err := pterm.DefaultTree.WithRoot(tree).Render(); err != nil { + + if err := pterm.DefaultTree.WithRoot(tree).WithWriter(utils.NewPTermWriter(pterm.Warning)).Render(); err != nil { l.Warn("failed to render missed resources", "error", err) } } diff --git a/cmd/provision/web.go b/cmd/provision/web.go index 67f2b2c..2772b7d 100644 --- a/cmd/provision/web.go +++ b/cmd/provision/web.go @@ -10,6 +10,7 @@ import ( googletagmanagerprovider "github.com/foomo/sesamy-cli/pkg/provider/googletagmanager" hotjarprovider "github.com/foomo/sesamy-cli/pkg/provider/hotjar" "github.com/foomo/sesamy-cli/pkg/tagmanager" + "github.com/foomo/sesamy-cli/pkg/utils" "github.com/pkg/errors" "github.com/pterm/pterm" "github.com/spf13/cobra" @@ -112,7 +113,7 @@ func NewWeb(root *cobra.Command) { } tree.Children = append(tree.Children, child) } - if err := pterm.DefaultTree.WithRoot(tree).Render(); err != nil { + if err := pterm.DefaultTree.WithRoot(tree).WithWriter(utils.NewPTermWriter(pterm.Warning)).Render(); err != nil { l.Warn("failed to render missed resources", "error", err) } } diff --git a/cmd/root.go b/cmd/root.go index 25936b2..9b18404 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -95,7 +95,6 @@ func Execute() { if err := root.Execute(); err != nil { pterm.Error.Println(say(strings.Split(errors.Cause(err).Error(), ":")[0])) pterm.Error.Println(err.Error()) - pterm.Error.Println(root.UsageString()) code = 1 } } diff --git a/pkg/utils/ptermwriter.go b/pkg/utils/ptermwriter.go new file mode 100644 index 0000000..a0b8350 --- /dev/null +++ b/pkg/utils/ptermwriter.go @@ -0,0 +1,20 @@ +package utils + +import ( + "github.com/pterm/pterm" +) + +type PTermWriter struct { + printer pterm.PrefixPrinter +} + +func NewPTermWriter(printer pterm.PrefixPrinter) *PTermWriter { + return &PTermWriter{ + printer: printer, + } +} + +func (p *PTermWriter) Write(b []byte) (int, error) { + p.printer.Println(string(b)) + return len(b), nil +}