Skip to content

Commit

Permalink
fix linter error messages
Browse files Browse the repository at this point in the history
golangci-lint reported "printf: non-constant format string in call..." which happens if the format string of a printf like function is a variable and not a constant.
  • Loading branch information
thirdeyenick committed Jan 20, 2025
1 parent 85b1b32 commit 36629f9
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 9 deletions.
2 changes: 1 addition & 1 deletion auth/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ func login(ctx context.Context, newConfig *clientcmdapi.Config, kubeconfigPath,
if strings.TrimSpace(userName) != "" {
loginMessage = fmt.Sprintf("logged into cluster %s as %s", newConfig.CurrentContext, userName)
}
format.PrintSuccessf("🚀", loginMessage)
format.PrintSuccess("🚀", loginMessage)

return nil
}
Expand Down
2 changes: 1 addition & 1 deletion create/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ func (app *applicationCmd) Run(ctx context.Context, client *api.Client) error {
}

func spinnerMessage(msg, icon string, sleepTime time.Duration) error {
fullMsg := format.ProgressMessagef(icon, msg)
fullMsg := format.ProgressMessage(icon, msg)
spinner, err := format.NewSpinner(fullMsg, fullMsg)
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ func (m *message) progress() string {
return ""
}

return format.ProgressMessagef(m.icon, m.text)
return format.ProgressMessage(m.icon, m.text)
}

func (m *message) printSuccess() {
if m.disabled {
return
}

format.PrintSuccessf(m.icon, m.text)
format.PrintSuccess(m.icon, m.text)
}

func newCreator(client *api.Client, mg resource.Managed, resourceName string) *creator {
Expand Down
2 changes: 1 addition & 1 deletion delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (d *deleter) deleteResource(ctx context.Context, client *api.Client, waitTi
}

if !force {
ok, err := format.Confirmf(d.prompt(d.kind, d.mg.GetName()))
ok, err := format.Confirm(d.prompt(d.kind, d.mg.GetName()))
if err != nil {
return err
}
Expand Down
31 changes: 27 additions & 4 deletions internal/format/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,32 @@ func ProgressMessagef(icon, format string, a ...any) string {
return fmt.Sprintf(" %s %s", fmt.Sprintf(format, a...), icon)
}

// ProgressMessage is a formatted message for use with a spinner.Suffix. An
// icon can be added which is displayed at the end of the message.
func ProgressMessage(icon, message string) string {
return fmt.Sprintf(" %s %s", message, icon)
}

// SuccessMessagef is a formatted message for indicating a successful step.
func SuccessMessagef(icon, format string, a ...any) string {
return fmt.Sprintf(" %s %s %s", SuccessChar, fmt.Sprintf(format, a...), icon)
}

// SuccessMessage returns a message for indicating a successful step.
func SuccessMessage(icon, message string) string {
return fmt.Sprintf(" %s %s %s", SuccessChar, message, icon)
}

// PrintSuccessf prints a success message.
func PrintSuccessf(icon, format string, a ...any) {
fmt.Print(SuccessMessagef(icon, format, a...) + "\n")
}

// PrintSuccess prints a success message.
func PrintSuccess(icon, message string) {
fmt.Print(SuccessMessage(icon, message) + "\n")
}

// FailureMessagef is a formatted message for indicating a failed step.
func FailureMessagef(icon, format string, a ...any) string {
return fmt.Sprintf(" %s %s %s", FailureChar, fmt.Sprintf(format, a...), icon)
Expand All @@ -64,12 +80,13 @@ func PrintWarningf(msg string, a ...any) {
fmt.Printf(color.YellowString("Warning: ")+msg, a...)
}

// Confirmf prints a confirm dialog using format and then waits until prompt
// is confirmed or denied. Only y and yes are accepted for confirmation.
func Confirmf(format string, a ...any) (bool, error) {
// Confirm prints a confirm dialog using the supplied message and then waits
// until prompt is confirmed or denied. Only y and yes are accepted for
// confirmation.
func Confirm(message string) (bool, error) {
var input string

fmt.Printf("%s [y|n]: ", fmt.Sprintf(format, a...))
fmt.Printf("%s [y|n]: ", message)
_, err := fmt.Scanln(&input)
if err != nil {
return false, err
Expand All @@ -82,6 +99,12 @@ func Confirmf(format string, a ...any) (bool, error) {
return false, nil
}

// Confirmf prints a confirm dialog using format and then waits until prompt
// is confirmed or denied. Only y and yes are accepted for confirmation.
func Confirmf(format string, a ...any) (bool, error) {
return Confirm(fmt.Sprintf(format, a...))
}

// NewSpinner returns a new spinner with the default config
func NewSpinner(message, stopMessage string) (*yacspin.Spinner, error) {
return yacspin.New(spinnerConfig(message, stopMessage))
Expand Down

0 comments on commit 36629f9

Please sign in to comment.