From cc2aa4aa42698ab5104594f5f69fdb736674b1db Mon Sep 17 00:00:00 2001 From: Sergiu Ghitea <28300158+sergiught@users.noreply.github.com> Date: Wed, 18 Jan 2023 20:40:49 +0100 Subject: [PATCH] Fix how we check if we should prompt when no flags set on cmd invocation --- internal/cli/cli.go | 11 +++++------ internal/cli/flags.go | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/internal/cli/cli.go b/internal/cli/cli.go index 944584d3c..f788f81c2 100644 --- a/internal/cli/cli.go +++ b/internal/cli/cli.go @@ -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) { diff --git a/internal/cli/flags.go b/internal/cli/flags.go index 08837f1c9..dff59a540 100644 --- a/internal/cli/flags.go +++ b/internal/cli/flags.go @@ -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)