Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions internal/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
"github.com/stackitcloud/stackit-cli/internal/pkg/print"

"github.com/fatih/color"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
Expand Down Expand Up @@ -96,7 +95,7 @@ func NewRootCmd(version, date string, p *print.Printer) *cobra.Command {
}

func beautifyUsageTemplate(cmd *cobra.Command) {
cobra.AddTemplateFunc("WhiteBold", color.New(color.FgHiWhite, color.Bold).SprintFunc())
cobra.AddTemplateFunc("WhiteBold", print.WhiteBold)
usageTemplate := cmd.UsageTemplate()
usageTemplate = strings.NewReplacer(
`Usage:`, `{{WhiteBold "USAGE"}}`,
Expand Down
13 changes: 10 additions & 3 deletions internal/pkg/print/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"os/exec"
"strings"

"github.com/fatih/color"
"github.com/lmittmann/tint"
"github.com/mattn/go-colorable"
"github.com/spf13/cobra"
Expand All @@ -33,7 +34,13 @@ const (
YAMLOutputFormat = "yaml"
)

var errAborted = errors.New("operation aborted")
var (
errAborted = errors.New("operation aborted")

WhiteBold = color.New(color.FgHiWhite, color.Bold).SprintFunc()
RedBold = color.New(color.FgHiRed, color.Bold).SprintFunc()
YellowBold = color.New(color.FgHiYellow, color.Bold).SprintFunc()
)

type Printer struct {
Cmd *cobra.Command
Expand Down Expand Up @@ -106,13 +113,13 @@ func (p *Printer) Warn(msg string, args ...any) {
return
}
warning := fmt.Sprintf(msg, args...)
p.Cmd.PrintErrf("Warning: %s", warning)
p.Cmd.PrintErrf("%s %s", YellowBold("Warning:"), warning)
}

// Print an Error level output to the defined Err output (falling back to Stderr if not set).
func (p *Printer) Error(msg string, args ...any) {
err := fmt.Sprintf(msg, args...)
p.Cmd.PrintErrln(p.Cmd.ErrPrefix(), err)
p.Cmd.PrintErrln(RedBold(p.Cmd.ErrPrefix()), err)
}

// Prompts the user for confirmation.
Expand Down