diff --git a/pkg/cli/api.go b/pkg/cli/api.go index d96a79064d3..0908727e2d2 100644 --- a/pkg/cli/api.go +++ b/pkg/cli/api.go @@ -14,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. */ -//nolint:dupl package cli import ( @@ -37,6 +36,19 @@ func (c CLI) newCreateAPICmd() *cobra.Command { ), } + // Show hint message on how to list flags instead of showing file completion + 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 more 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/cmd_helpers.go b/pkg/cli/cmd_helpers.go index b6af5ef4dc9..34aec048a58 100644 --- a/pkg/cli/cmd_helpers.go +++ b/pkg/cli/cmd_helpers.go @@ -268,6 +268,12 @@ func initializationHooks( var options *resourceOptions if requiresResource { options = bindResourceFlags(cmd.Flags()) + if err := cmd.MarkFlagRequired("version"); err != nil { + return nil, fmt.Errorf("failed to mark 'version' flag as required: %w", err) + } + if err := cmd.MarkFlagRequired("kind"); err != nil { + return nil, fmt.Errorf("failed to mark 'kind' flag as required: %w", err) + } } // Bind flags hook: each plugin binds to a temporary FlagSet, then we merge into the command so