Skip to content

Commit

Permalink
DXCDT-331: Fix how we check if we should prompt when no flags set on …
Browse files Browse the repository at this point in the history
…cmd invocation (#616)

Fix how we check if we should prompt when no flags set on cmd invocation
  • Loading branch information
sergiught authored Jan 18, 2023
1 parent 7184197 commit abe6c4c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
11 changes: 5 additions & 6 deletions internal/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,16 +536,15 @@ func shouldPrompt(cmd *cobra.Command, flag *Flag) bool {
return canPrompt(cmd) && !flag.IsSet(cmd)
}

func shouldPromptWhenFlagless(cmd *cobra.Command, flag string) bool {
isSet := false

func shouldPromptWhenNoLocalFlagsSet(cmd *cobra.Command) bool {
localFlagIsSet := false
cmd.LocalFlags().VisitAll(func(f *pflag.Flag) {
if f.Changed {
isSet = true
if f.Name != "json" && f.Name != "force" && f.Changed {
localFlagIsSet = true
}
})

return canPrompt(cmd) && !isSet
return canPrompt(cmd) && !localFlagIsSet
}

func prepareInteractivity(cmd *cobra.Command) {
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ func shouldAsk(cmd *cobra.Command, f *Flag, isUpdate bool) bool {
if !f.IsRequired && !f.AlwaysPrompt {
return false
}
return shouldPromptWhenFlagless(cmd, f.LongForm)
return shouldPromptWhenNoLocalFlagsSet(cmd)
}

return shouldPrompt(cmd, f)
Expand Down

0 comments on commit abe6c4c

Please sign in to comment.