fix: use warning logger

This commit is contained in:
Kevin Franklin Kim 2025-03-20 16:45:25 +01:00
parent 0617588911
commit bc28c78ad8
No known key found for this signature in database
4 changed files with 25 additions and 3 deletions

View File

@ -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)
}
}

View File

@ -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)
}
}

View File

@ -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
}
}

20
pkg/utils/ptermwriter.go Normal file
View File

@ -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
}