diff --git a/.chloggen/otelcol-featuregate-max-args.yaml b/.chloggen/otelcol-featuregate-max-args.yaml new file mode 100644 index 00000000000..744cf560ecf --- /dev/null +++ b/.chloggen/otelcol-featuregate-max-args.yaml @@ -0,0 +1,4 @@ +change_type: bug_fix +component: pkg/otelcol +note: The featuregate subcommand now rejects extra positional arguments instead of silently ignoring them. +issues: [14554] diff --git a/otelcol/command.go b/otelcol/command.go index 88f3b9a818e..a129b9f1d79 100644 --- a/otelcol/command.go +++ b/otelcol/command.go @@ -75,6 +75,7 @@ func newFeatureGateCommand() *cobra.Command { Use: "featuregate [feature-id]", Short: "Display feature gates information", Long: "Display information about available feature gates and their status", + Args: cobra.MaximumNArgs(1), RunE: func(_ *cobra.Command, args []string) error { if len(args) > 0 { found := false diff --git a/otelcol/command_test.go b/otelcol/command_test.go index 56445eea4f3..46f8290f1a1 100644 --- a/otelcol/command_test.go +++ b/otelcol/command_test.go @@ -216,4 +216,11 @@ func TestNewFeatureGateCommand(t *testing.T) { require.Error(t, err) assert.Contains(t, err.Error(), "feature \"non.existent.feature\" not found") }) + + t.Run("rejects multiple arguments", func(t *testing.T) { + cmd := newFeatureGateCommand() + cmd.SetArgs([]string{"gate1", "gate2"}) + err := cmd.Execute() + require.Error(t, err) + }) }