Update delete command

This commit is contained in:
Seth Vargo
2017-09-07 21:59:06 -04:00
parent 36eccfb424
commit 6b75e6e2bf
2 changed files with 13 additions and 15 deletions

View File

@@ -8,17 +8,15 @@ import (
"github.com/posener/complete" "github.com/posener/complete"
) )
// Ensure we are implementing the right interfaces.
var _ cli.Command = (*DeleteCommand)(nil) var _ cli.Command = (*DeleteCommand)(nil)
var _ cli.CommandAutocomplete = (*DeleteCommand)(nil) var _ cli.CommandAutocomplete = (*DeleteCommand)(nil)
// DeleteCommand is a Command that puts data into the Vault.
type DeleteCommand struct { type DeleteCommand struct {
*BaseCommand *BaseCommand
} }
func (c *DeleteCommand) Synopsis() string { func (c *DeleteCommand) Synopsis() string {
return "Deletes secrets and configuration" return "Delete secrets and configuration"
} }
func (c *DeleteCommand) Help() string { func (c *DeleteCommand) Help() string {
@@ -69,13 +67,11 @@ func (c *DeleteCommand) Run(args []string) int {
} }
args = f.Args() args = f.Args()
path, kvs, err := extractPath(args) switch {
if err != nil { case len(args) < 1:
c.UI.Error(err.Error()) c.UI.Error(fmt.Sprintf("Not enough arguments (expected 1, got %d)", len(args)))
return 1 return 1
} case len(args) > 1:
if len(kvs) > 0 {
c.UI.Error(fmt.Sprintf("Too many arguments (expected 1, got %d)", len(args))) c.UI.Error(fmt.Sprintf("Too many arguments (expected 1, got %d)", len(args)))
return 1 return 1
} }
@@ -86,6 +82,8 @@ func (c *DeleteCommand) Run(args []string) int {
return 2 return 2
} }
path := sanitizePath(args[0])
if _, err := client.Logical().Delete(path); err != nil { if _, err := client.Logical().Delete(path); err != nil {
c.UI.Error(fmt.Sprintf("Error deleting %s: %s", path, err)) c.UI.Error(fmt.Sprintf("Error deleting %s: %s", path, err))
return 2 return 2

View File

@@ -28,15 +28,15 @@ func TestDeleteCommand_Run(t *testing.T) {
code int code int
}{ }{
{ {
"empty", "not_enough_args",
nil, []string{},
"Missing PATH!", "Not enough arguments",
1, 1,
}, },
{ {
"slash", "too_many_args",
[]string{"/"}, []string{"foo", "bar"},
"Missing PATH!", "Too many arguments",
1, 1,
}, },
} }