command: error on invalid plugins remove

If a user attempts to remove a plugin through the `packer plugins
remove' subcommand, and the specified plugin is not installed, the
command succeeds, but does nothing, and exits silently.

This is not clear what is happening, and arguably, calling a command
that does nothing, not even explain what went wrong, is not intuitive.

Because of that, this commit changes how the command behaves in this
case, stating what went wrong, and exiting with a non-zero status.
pull/12678/head
Lucas Bajolet 3 years ago committed by Lucas Bajolet
parent c528681dde
commit f221a799d8

@ -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
}

@ -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=",
},

Loading…
Cancel
Save