diff --git a/command/plugin_status.go b/command/plugin_status.go index 6f3a1980c65..a60430539de 100644 --- a/command/plugin_status.go +++ b/command/plugin_status.go @@ -110,8 +110,6 @@ func (c *PluginStatusCommand) Run(args []string) int { return 1 } - typeArg = strings.ToLower(typeArg) - // Check that we either got no arguments or exactly one. args = flags.Args() if len(args) > 1 { @@ -120,6 +118,17 @@ func (c *PluginStatusCommand) Run(args []string) int { return 1 } + typeArg = strings.ToLower(typeArg) + + // Check that the plugin type flag is supported. Empty implies we are + // querying all plugins, otherwise we currently only support "csi". + switch typeArg { + case "", "csi": + default: + c.Ui.Error(fmt.Sprintf("Unsupported plugin type: %s", typeArg)) + return 1 + } + // Truncate the id unless full length is requested c.length = shortId if c.verbose { diff --git a/command/plugin_status_test.go b/command/plugin_status_test.go index e0cb4920d5f..15f037c2422 100644 --- a/command/plugin_status_test.go +++ b/command/plugin_status_test.go @@ -27,6 +27,14 @@ func TestPluginStatusCommand_Fails(t *testing.T) { out := ui.ErrorWriter.String() require.Contains(t, out, commandErrorText(cmd)) ui.ErrorWriter.Reset() + + // Test an unsupported plugin type. + code = cmd.Run([]string{"-type=not-a-plugin"}) + require.Equal(t, 1, code) + + out = ui.ErrorWriter.String() + require.Contains(t, out, "Unsupported plugin type: not-a-plugin") + ui.ErrorWriter.Reset() } func TestPluginStatusCommand_AutocompleteArgs(t *testing.T) {