Skip to content

Commit

Permalink
Fix flag issues on apps create and apps update [CLI-146] (#269)
Browse files Browse the repository at this point in the history
* Fix flag value retention on apps create and update

* Use the new IsSet method
  • Loading branch information
Widcket authored Apr 30, 2021
1 parent 8f52e8f commit 457d3ff
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion internal/cli/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
16 changes: 8 additions & 8 deletions internal/cli/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ auth0 apps create -n myapp -t [native|spa|regular|m2m] -- description <descripti
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 {
Expand All @@ -368,7 +368,7 @@ auth0 apps create -n myapp -t [native|spa|regular|m2m] -- description <descripti
}

// Prompt for logout URLs if app is not m2m
if !appIsM2M {
if !appIsM2M && !appLogoutURLs.IsSet(cmd) {
var defaultValue string

if !appIsNative {
Expand All @@ -381,7 +381,7 @@ auth0 apps create -n myapp -t [native|spa|regular|m2m] -- description <descripti
}

// Prompt for allowed origins URLs if app is SPA
if appIsSPA {
if appIsSPA && !appOrigins.IsSet(cmd) {
defaultValue := appDefaultURL

if err := appOrigins.AskMany(cmd, &inputs.AllowedOrigins, &defaultValue); err != nil {
Expand All @@ -390,7 +390,7 @@ auth0 apps create -n myapp -t [native|spa|regular|m2m] -- description <descripti
}

// Prompt for allowed web origins URLs if app is SPA
if appIsSPA {
if appIsSPA && !appWebOrigins.IsSet(cmd) {
defaultValue := appDefaultURL

if err := appWebOrigins.AskMany(cmd, &inputs.AllowedWebOrigins, &defaultValue); err != nil {
Expand Down Expand Up @@ -519,7 +519,7 @@ auth0 apps update <id> -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 {
Expand All @@ -536,7 +536,7 @@ auth0 apps update <id> -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 {
Expand All @@ -553,7 +553,7 @@ auth0 apps update <id> -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 {
Expand All @@ -566,7 +566,7 @@ auth0 apps update <id> -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 {
Expand Down
4 changes: 4 additions & 0 deletions internal/cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ auth0 rules update <rule-id> -n "My Updated Rule" --enabled=false`,
return err
}

if !cmd.Flags().Changed(ruleEnabled.LongForm) {
if !ruleEnabled.IsSet(cmd) {
inputs.Enabled = auth0.BoolValue(rule.Enabled)
}

Expand Down

0 comments on commit 457d3ff

Please sign in to comment.