From 0c9a20bf365c41f2d13ba3a5b2bf392834af2378 Mon Sep 17 00:00:00 2001 From: r-vasquez Date: Thu, 30 May 2024 09:02:03 -0700 Subject: [PATCH] rpk: explicitly add Arg validation to plugins In #18650 we added Arg validations for every comman and an automatic "walk" through the command space to add cobra.NoArgs. Plugins were not taken into account, this commit explicitly set the cobra.MinimumArg(0) to avoid adding "NoArgs" on execution. --- src/go/rpk/pkg/cli/plugin_cmds.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/go/rpk/pkg/cli/plugin_cmds.go b/src/go/rpk/pkg/cli/plugin_cmds.go index bc7bc07a4ff37..c7b24aa9492a1 100644 --- a/src/go/rpk/pkg/cli/plugin_cmds.go +++ b/src/go/rpk/pkg/cli/plugin_cmds.go @@ -88,6 +88,7 @@ func addPluginWithExec( Use: p0, Short: p0 + pluginShortSuffix, DisableFlagParsing: true, + Args: cobra.MinimumNArgs(0), Run: func(cmd *cobra.Command, args []string) { keepForPlugin, _ := cobraext.StripFlagset(args, cmd.InheritedFlags()) // strip all rpk specific flags before execing the plugin err := osExec(execPath, keepForPlugin) @@ -263,6 +264,7 @@ func addPluginSubcommands( childCmd := &cobra.Command{ Short: fmt.Sprintf("%s external plugin", childUse), DisableFlagParsing: true, + Args: cobra.MinimumNArgs(0), Run: func(cmd *cobra.Command, args []string) { keepForPlugin, _ := cobraext.StripFlagset(args, cmd.InheritedFlags()) // strip all rpk specific flags before execing the plugin osExec(execPath, append(append(leadingPieces, cmd.Use), keepForPlugin...))