Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DXCDT-331: Fix how we check if we should prompt when no flags set on cmd invocation #616

Merged
merged 2 commits into from
Jan 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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