Update delete command
This commit is contained in:
parent
810c0afe38
commit
02341c3b6a
|
@ -8,17 +8,15 @@ import (
|
|||
"github.com/posener/complete"
|
||||
)
|
||||
|
||||
// Ensure we are implementing the right interfaces.
|
||||
var _ cli.Command = (*DeleteCommand)(nil)
|
||||
var _ cli.CommandAutocomplete = (*DeleteCommand)(nil)
|
||||
|
||||
// DeleteCommand is a Command that puts data into the Vault.
|
||||
type DeleteCommand struct {
|
||||
*BaseCommand
|
||||
}
|
||||
|
||||
func (c *DeleteCommand) Synopsis() string {
|
||||
return "Deletes secrets and configuration"
|
||||
return "Delete secrets and configuration"
|
||||
}
|
||||
|
||||
func (c *DeleteCommand) Help() string {
|
||||
|
@ -69,13 +67,11 @@ func (c *DeleteCommand) Run(args []string) int {
|
|||
}
|
||||
|
||||
args = f.Args()
|
||||
path, kvs, err := extractPath(args)
|
||||
if err != nil {
|
||||
c.UI.Error(err.Error())
|
||||
switch {
|
||||
case len(args) < 1:
|
||||
c.UI.Error(fmt.Sprintf("Not enough arguments (expected 1, got %d)", len(args)))
|
||||
return 1
|
||||
}
|
||||
|
||||
if len(kvs) > 0 {
|
||||
case len(args) > 1:
|
||||
c.UI.Error(fmt.Sprintf("Too many arguments (expected 1, got %d)", len(args)))
|
||||
return 1
|
||||
}
|
||||
|
@ -86,6 +82,8 @@ func (c *DeleteCommand) Run(args []string) int {
|
|||
return 2
|
||||
}
|
||||
|
||||
path := sanitizePath(args[0])
|
||||
|
||||
if _, err := client.Logical().Delete(path); err != nil {
|
||||
c.UI.Error(fmt.Sprintf("Error deleting %s: %s", path, err))
|
||||
return 2
|
||||
|
|
|
@ -28,15 +28,15 @@ func TestDeleteCommand_Run(t *testing.T) {
|
|||
code int
|
||||
}{
|
||||
{
|
||||
"empty",
|
||||
nil,
|
||||
"Missing PATH!",
|
||||
"not_enough_args",
|
||||
[]string{},
|
||||
"Not enough arguments",
|
||||
1,
|
||||
},
|
||||
{
|
||||
"slash",
|
||||
[]string{"/"},
|
||||
"Missing PATH!",
|
||||
"too_many_args",
|
||||
[]string{"foo", "bar"},
|
||||
"Too many arguments",
|
||||
1,
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue