From bb1d9b402ace0b27cccaeacba840233055f7f816 Mon Sep 17 00:00:00 2001 From: Enda Date: Mon, 29 Mar 2021 11:20:47 +0100 Subject: [PATCH] fix(serviceaccount): fix invalid i18n message (#509) --- pkg/cmd/flag/flag.go | 1 + pkg/cmd/serviceaccount/create/create.go | 9 ++------- .../serviceaccount/resetcredentials/reset_credentials.go | 9 ++------- 3 files changed, 5 insertions(+), 14 deletions(-) diff --git a/pkg/cmd/flag/flag.go b/pkg/cmd/flag/flag.go index 8dd97637b..2ac458d0e 100644 --- a/pkg/cmd/flag/flag.go +++ b/pkg/cmd/flag/flag.go @@ -18,6 +18,7 @@ func (e *Error) Unwrap() error { return e.Err } +// InvalidValueError returns an error when an invalid flag value is provided func InvalidValueError(flag string, val interface{}, validOptions ...string) *Error { var chooseFromStr string if len(validOptions) > 0 { diff --git a/pkg/cmd/serviceaccount/create/create.go b/pkg/cmd/serviceaccount/create/create.go index 7347f353a..e350b0f79 100644 --- a/pkg/cmd/serviceaccount/create/create.go +++ b/pkg/cmd/serviceaccount/create/create.go @@ -16,6 +16,7 @@ import ( "github.com/bf2fc6cc711aee1a0c2a/cli/internal/config" "github.com/bf2fc6cc711aee1a0c2a/cli/internal/localizer" "github.com/bf2fc6cc711aee1a0c2a/cli/pkg/cmd/factory" + "github.com/bf2fc6cc711aee1a0c2a/cli/pkg/cmd/flag" "github.com/bf2fc6cc711aee1a0c2a/cli/pkg/logging" "github.com/spf13/cobra" ) @@ -73,13 +74,7 @@ func NewCreateCommand(f *factory.Factory) *cobra.Command { // check that a valid --file-format flag value is used validOutput := flagutil.IsValidInput(opts.fileFormat, flagutil.CredentialsOutputFormats...) if !validOutput && opts.fileFormat != "" { - return fmt.Errorf(localizer.MustLocalize(&localizer.Config{ - MessageID: "flag.error.invalidValue", - TemplateData: map[string]interface{}{ - "Flag": "file-format", - "Value": opts.fileFormat, - }, - })) + return flag.InvalidValueError("file-format", opts.fileFormat, flagutil.CredentialsOutputFormats...) } return runCreate(opts) diff --git a/pkg/cmd/serviceaccount/resetcredentials/reset_credentials.go b/pkg/cmd/serviceaccount/resetcredentials/reset_credentials.go index 955fbe82c..3a57ce37f 100644 --- a/pkg/cmd/serviceaccount/resetcredentials/reset_credentials.go +++ b/pkg/cmd/serviceaccount/resetcredentials/reset_credentials.go @@ -16,6 +16,7 @@ import ( "github.com/bf2fc6cc711aee1a0c2a/cli/internal/config" "github.com/bf2fc6cc711aee1a0c2a/cli/internal/localizer" "github.com/bf2fc6cc711aee1a0c2a/cli/pkg/cmd/factory" + "github.com/bf2fc6cc711aee1a0c2a/cli/pkg/cmd/flag" "github.com/bf2fc6cc711aee1a0c2a/cli/pkg/logging" "github.com/spf13/cobra" ) @@ -72,13 +73,7 @@ func NewResetCredentialsCommand(f *factory.Factory) *cobra.Command { validOutput := flagutil.IsValidInput(opts.fileFormat, flagutil.CredentialsOutputFormats...) if !validOutput && opts.fileFormat != "" { - return fmt.Errorf(localizer.MustLocalize(&localizer.Config{ - MessageID: "flag.error.invalidValue", - TemplateData: map[string]interface{}{ - "Flag": "file-format", - "Value": opts.fileFormat, - }, - })) + return flag.InvalidValueError("file-format", opts.fileFormat, flagutil.CredentialsOutputFormats...) } return runResetCredentials(opts)