diff --git a/auth/login.go b/auth/login.go index 5666ed3..cfa54c9 100644 --- a/auth/login.go +++ b/auth/login.go @@ -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 } diff --git a/create/application.go b/create/application.go index 312e057..89e4b5c 100644 --- a/create/application.go +++ b/create/application.go @@ -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 diff --git a/create/create.go b/create/create.go index 2230fb1..4a5a998 100644 --- a/create/create.go +++ b/create/create.go @@ -82,7 +82,7 @@ func (m *message) progress() string { return "" } - return format.ProgressMessagef(m.icon, m.text) + return format.ProgressMessage(m.icon, m.text) } func (m *message) printSuccess() { @@ -90,7 +90,7 @@ func (m *message) printSuccess() { return } - format.PrintSuccessf(m.icon, m.text) + format.PrintSuccess(m.icon, m.text) } func newCreator(client *api.Client, mg resource.Managed, resourceName string) *creator { diff --git a/delete/delete.go b/delete/delete.go index a1186aa..4e57eac 100644 --- a/delete/delete.go +++ b/delete/delete.go @@ -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 } diff --git a/internal/format/print.go b/internal/format/print.go index af6befc..4a1a713 100644 --- a/internal/format/print.go +++ b/internal/format/print.go @@ -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) @@ -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 @@ -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))