diff --git a/command/plugins_remove.go b/command/plugins_remove.go index 624a632e525..5c13636f5c6 100644 --- a/command/plugins_remove.go +++ b/command/plugins_remove.go @@ -104,5 +104,14 @@ func (c *PluginsRemoveCommand) RunContext(buildCtx context.Context, args []strin c.Ui.Message(installation.BinaryPath) } + if len(installations) == 0 { + errMsg := fmt.Sprintf("No installed plugin found matching the plugin constraints %s", args[0]) + if len(args) == 2 { + errMsg = fmt.Sprintf("%s %s", errMsg, args[1]) + } + c.Ui.Error(errMsg) + return 1 + } + return 0 } diff --git a/command/plugins_remove_test.go b/command/plugins_remove_test.go index dcaafb98e5d..4149ceaeb9c 100644 --- a/command/plugins_remove_test.go +++ b/command/plugins_remove_test.go @@ -47,7 +47,7 @@ func TestPluginsRemoveCommand_Run(t *testing.T) { expectedPackerConfigDirHashBeforeRemove: "h1:Q5qyAOdD43hL3CquQdVfaHpOYGf0UsZ/+wVA9Ry6cbA=", packerConfigDir: cfg.dir("1_pkr_plugins_config"), pluginSourceArgs: []string{"github.com/sylviamoss/comment", "v0.2.19"}, - want: 0, + want: 1, dirFiles: nil, expectedPackerConfigDirHashAfterRemove: "h1:Q5qyAOdD43hL3CquQdVfaHpOYGf0UsZ/+wVA9Ry6cbA=", }, @@ -158,7 +158,7 @@ func TestPluginsRemoveCommand_Run(t *testing.T) { expectedPackerConfigDirHashBeforeRemove: "h1:47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=", packerConfigDir: cfg.dir("3_pkr_plugins_config"), pluginSourceArgs: []string{"example.com/sylviamoss/comment", "v0.2.19"}, - want: 0, + want: 1, dirFiles: nil, expectedPackerConfigDirHashAfterRemove: "h1:47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=", },