forked from gopasspw/gopass
/
delete.go
44 lines (35 loc) · 947 Bytes
/
delete.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package action
import (
"fmt"
"github.com/justwatchcom/gopass/password"
"github.com/urfave/cli"
)
// Delete a secret file with its content
func (s *Action) Delete(c *cli.Context) error {
force := c.Bool("force")
recursive := c.Bool("recursive")
name := c.Args().First()
if name == "" {
return fmt.Errorf("provide a secret name")
}
found, err := s.Store.Exists(name)
if err != nil && err != password.ErrNotFound {
return fmt.Errorf("failed to see if %s exists", name)
}
if !force { // don't check if it's force anyway
recStr := ""
if recursive {
recStr = "recursively "
}
if found && !askForConfirmation(fmt.Sprintf("Are you sure you would like to %sdelete %s?", recStr, name)) {
return nil
}
}
if recursive {
return s.Store.Prune(name)
}
if s.Store.IsDir(name) {
return fmt.Errorf("Cannot remove '%s': Is a directory. Use 'gopass rm -r %s' to delete", name, name)
}
return s.Store.Delete(name)
}