From 457d3ff07f6c32b7bbe94919bc98fd9d6d7748f1 Mon Sep 17 00:00:00 2001 From: Rita Zerrizuela Date: Fri, 30 Apr 2021 12:07:42 -0300 Subject: [PATCH] Fix flag issues on `apps create` and `apps update` [CLI-146] (#269) * Fix flag value retention on apps create and update * Use the new IsSet method --- internal/cli/apis.go | 2 +- internal/cli/apps.go | 16 ++++++++-------- internal/cli/flags.go | 4 ++++ internal/cli/rules.go | 2 +- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/internal/cli/apis.go b/internal/cli/apis.go index b5200b7eb..07b7bb49e 100644 --- a/internal/cli/apis.go +++ b/internal/cli/apis.go @@ -289,7 +289,7 @@ auth0 apis update -n myapi -e 6100 --offline-access=true`, return err } - if !cmd.Flags().Changed(apiOfflineAccess.LongForm) { + if !apiOfflineAccess.IsSet(cmd) { inputs.AllowOfflineAccess = auth0.BoolValue(current.AllowOfflineAccess) } diff --git a/internal/cli/apps.go b/internal/cli/apps.go index 43763647c..5cdc9a81e 100644 --- a/internal/cli/apps.go +++ b/internal/cli/apps.go @@ -355,7 +355,7 @@ auth0 apps create -n myapp -t [native|spa|regular|m2m] -- description -n myapp --type [native|spa|regular|m2m]`, appIsSPA := apiTypeFor(inputs.Type) == appTypeSPA // Prompt for callback URLs if app is not m2m - if !appIsM2M { + if !appIsM2M && !appCallbacks.IsSet(cmd) { var defaultValue string if !appIsNative { @@ -536,7 +536,7 @@ auth0 apps update -n myapp --type [native|spa|regular|m2m]`, } // Prompt for logout URLs if app is not m2m - if !appIsM2M { + if !appIsM2M && !appLogoutURLs.IsSet(cmd) { var defaultValue string if !appIsNative { @@ -553,7 +553,7 @@ auth0 apps update -n myapp --type [native|spa|regular|m2m]`, } // Prompt for allowed origins URLs if app is SPA - if appIsSPA { + if appIsSPA && !appOrigins.IsSet(cmd) { defaultValue := appDefaultURL if len(current.AllowedOrigins) > 0 { @@ -566,7 +566,7 @@ auth0 apps update -n myapp --type [native|spa|regular|m2m]`, } // Prompt for allowed web origins URLs if app is SPA - if appIsSPA { + if appIsSPA && !appWebOrigins.IsSet(cmd) { defaultValue := appDefaultURL if len(current.WebOrigins) > 0 { diff --git a/internal/cli/flags.go b/internal/cli/flags.go index 00d66f9b3..6bb1b9a59 100644 --- a/internal/cli/flags.go +++ b/internal/cli/flags.go @@ -33,6 +33,10 @@ func (f Flag) GetIsRequired() bool { return f.IsRequired } +func (f *Flag) IsSet(cmd *cobra.Command) bool { + return cmd.Flags().Changed(f.LongForm) +} + func (f *Flag) Ask(cmd *cobra.Command, value interface{}, defaultValue *string) error { return askFlag(cmd, f, value, defaultValue, false) } diff --git a/internal/cli/rules.go b/internal/cli/rules.go index cce1575e7..68000acea 100644 --- a/internal/cli/rules.go +++ b/internal/cli/rules.go @@ -313,7 +313,7 @@ auth0 rules update -n "My Updated Rule" --enabled=false`, return err } - if !cmd.Flags().Changed(ruleEnabled.LongForm) { + if !ruleEnabled.IsSet(cmd) { inputs.Enabled = auth0.BoolValue(rule.Enabled) }