cli: Improve error handling for plugin commands (#24250)

* Stop supporting vault plugin info and deregister without a type argument
* Make a best-effort attempt to report whether a plugin was actually deregistered and give more descriptive errors
* Fix error message for vault plugin reload
This commit is contained in:
Tom Proctor
2023-11-28 14:13:26 +00:00
committed by GitHub
parent 030bba4e68
commit 51d99fc7cf
7 changed files with 95 additions and 30 deletions

View File

@@ -77,23 +77,19 @@ func (c *PluginInfoCommand) Run(args []string) int {
var pluginNameRaw, pluginTypeRaw string
args = f.Args()
positionalArgsCount := len(args)
switch {
case len(args) < 1:
c.UI.Error(fmt.Sprintf("Not enough arguments (expected 1 or 2, got %d)", len(args)))
case positionalArgsCount < 2:
c.UI.Error(fmt.Sprintf("Not enough arguments (expected 2, got %d)", positionalArgsCount))
return 1
case len(args) > 2:
c.UI.Error(fmt.Sprintf("Too many arguments (expected 1 or 2, got %d)", len(args)))
case positionalArgsCount > 2:
c.UI.Error(fmt.Sprintf("Too many arguments (expected 2, got %d)", positionalArgsCount))
return 1
// These cases should come after invalid cases have been checked
case len(args) == 1:
pluginTypeRaw = "unknown"
pluginNameRaw = args[0]
case len(args) == 2:
pluginTypeRaw = args[0]
pluginNameRaw = args[1]
}
pluginTypeRaw = args[0]
pluginNameRaw = args[1]
client, err := c.Client()
if err != nil {
c.UI.Error(err.Error())