diff --git a/internal/cli/alpha/generate.go b/internal/cli/alpha/generate.go index 2ba671b0acf..63d6ce40b88 100644 --- a/internal/cli/alpha/generate.go +++ b/internal/cli/alpha/generate.go @@ -69,6 +69,20 @@ If no output directory is provided, the current working directory will be cleane }, } + // Show hint message on how to list flags instead of showing file completion for + // commands that don't take files as arguments + scaffoldCmd.ValidArgsFunction = func( + _ *cobra.Command, + args []string, + toComplete string, + ) ([]cobra.Completion, cobra.ShellCompDirective) { + completions := []cobra.Completion{} + if len(args) == 0 && toComplete == "" { + completions = cobra.AppendActiveHelp(completions, "Type '--' and press TAB to list flags") + } + return completions, cobra.ShellCompDirectiveNoFileComp + } + scaffoldCmd.Flags().StringVar(&opts.InputDir, "input-dir", "", "Path to the directory containing the PROJECT file. "+ "Defaults to the current working directory. WARNING: delete existing files (except .git and PROJECT).") diff --git a/internal/cli/alpha/update.go b/internal/cli/alpha/update.go index 299b9abce48..32cf2212930 100644 --- a/internal/cli/alpha/update.go +++ b/internal/cli/alpha/update.go @@ -144,6 +144,20 @@ Defaults: }, } + // Show hint message on how to list flags instead of showing file completion for + // commands that don't take files as arguments + updateCmd.ValidArgsFunction = func( + _ *cobra.Command, + args []string, + toComplete string, + ) ([]cobra.Completion, cobra.ShellCompDirective) { + completions := []cobra.Completion{} + if len(args) == 0 && toComplete == "" { + completions = cobra.AppendActiveHelp(completions, "Type '--' and press TAB to list flags") + } + return completions, cobra.ShellCompDirectiveNoFileComp + } + updateCmd.Flags().StringVar(&opts.FromVersion, "from-version", "", "binary release version to upgrade from. Should match the version used to init the project and be "+ "a valid release version, e.g., v4.6.0. If not set, it defaults to the version specified in the PROJECT file.") diff --git a/pkg/cli/api.go b/pkg/cli/api.go index d96a79064d3..f014c088784 100644 --- a/pkg/cli/api.go +++ b/pkg/cli/api.go @@ -37,6 +37,20 @@ func (c CLI) newCreateAPICmd() *cobra.Command { ), } + // Show hint message on how to list flags instead of showing file completion for + // commands that don't take files as arguments + cmd.ValidArgsFunction = func( + _ *cobra.Command, + args []string, + toComplete string, + ) ([]cobra.Completion, cobra.ShellCompDirective) { + completions := []cobra.Completion{} + if len(args) == 0 && toComplete == "" { + completions = cobra.AppendActiveHelp(completions, "Type '--' and press TAB to list flags") + } + return completions, cobra.ShellCompDirectiveNoFileComp + } + // In case no plugin was resolved, instead of failing the construction of the CLI, fail the execution of // this subcommand. This allows the use of subcommands that do not require resolved plugins like help. if len(c.resolvedPlugins) == 0 { diff --git a/pkg/cli/edit.go b/pkg/cli/edit.go index 1cf07a6a5bb..54885de0fbc 100644 --- a/pkg/cli/edit.go +++ b/pkg/cli/edit.go @@ -37,6 +37,20 @@ func (c CLI) newEditCmd() *cobra.Command { ), } + // Show hint message on how to list flags instead of showing file completion for + // commands that don't take files as arguments + cmd.ValidArgsFunction = func( + _ *cobra.Command, + args []string, + toComplete string, + ) ([]cobra.Completion, cobra.ShellCompDirective) { + completions := []cobra.Completion{} + if len(args) == 0 && toComplete == "" { + completions = cobra.AppendActiveHelp(completions, "Type '--' and press TAB to list flags") + } + return completions, cobra.ShellCompDirectiveNoFileComp + } + // In case no plugin was resolved, instead of failing the construction of the CLI, fail the execution of // this subcommand. This allows the use of subcommands that do not require resolved plugins like help. if len(c.resolvedPlugins) == 0 { diff --git a/pkg/cli/init.go b/pkg/cli/init.go index aaab049d13d..399e945b48a 100644 --- a/pkg/cli/init.go +++ b/pkg/cli/init.go @@ -42,6 +42,20 @@ For further help about a specific plugin, set --plugins. Run: func(_ *cobra.Command, _ []string) {}, } + // Show hint message on how to list flags instead of showing file completion for + // commands that don't take files as arguments + cmd.ValidArgsFunction = func( + _ *cobra.Command, + args []string, + toComplete string, + ) ([]cobra.Completion, cobra.ShellCompDirective) { + completions := []cobra.Completion{} + if len(args) == 0 && toComplete == "" { + completions = cobra.AppendActiveHelp(completions, "Type '--' and press TAB to list flags") + } + return completions, cobra.ShellCompDirectiveNoFileComp + } + // Register --project-version on the dynamically created command // so that it shows up in help and does not cause a parse error. cmd.Flags().String(projectVersionFlag, c.defaultProjectVersion.String(), "project version") diff --git a/pkg/cli/version.go b/pkg/cli/version.go index f721c41ff0f..b4cc9ffb8c8 100644 --- a/pkg/cli/version.go +++ b/pkg/cli/version.go @@ -33,5 +33,20 @@ func (c CLI) newVersionCmd() *cobra.Command { return nil }, } + + // Show hint message on how to list flags instead of showing file completion for + // commands that don't take files as arguments + cmd.ValidArgsFunction = func( + _ *cobra.Command, + args []string, + toComplete string, + ) ([]cobra.Completion, cobra.ShellCompDirective) { + completions := []cobra.Completion{} + if len(args) == 0 && toComplete == "" { + completions = cobra.AppendActiveHelp(completions, "Type '--' and press TAB to list flags") + } + return completions, cobra.ShellCompDirectiveNoFileComp + } + return cmd } diff --git a/pkg/cli/webhook.go b/pkg/cli/webhook.go index a07aaee094d..e8e969b4f5d 100644 --- a/pkg/cli/webhook.go +++ b/pkg/cli/webhook.go @@ -37,6 +37,20 @@ func (c CLI) newCreateWebhookCmd() *cobra.Command { ), } + // Show hint message on how to list flags instead of showing file completion for + // commands that don't take files as arguments + cmd.ValidArgsFunction = func( + _ *cobra.Command, + args []string, + toComplete string, + ) ([]cobra.Completion, cobra.ShellCompDirective) { + completions := []cobra.Completion{} + if len(args) == 0 && toComplete == "" { + completions = cobra.AppendActiveHelp(completions, "Type '--' and press TAB to list flags") + } + return completions, cobra.ShellCompDirectiveNoFileComp + } + // In case no plugin was resolved, instead of failing the construction of the CLI, fail the execution of // this subcommand. This allows the use of subcommands that do not require resolved plugins like help. if len(c.resolvedPlugins) == 0 {