-
Notifications
You must be signed in to change notification settings - Fork 1
/
rm.go
55 lines (44 loc) · 1.06 KB
/
rm.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
45
46
47
48
49
50
51
52
53
54
55
package vault
import (
"fmt"
"github.com/pvwnthem/gopwd/constants"
"github.com/pvwnthem/gopwd/pkg/util"
"github.com/spf13/cobra"
)
var removeCmd = &cobra.Command{
Use: "rm",
Short: "Removes an existing vault at the specified path",
Long: "",
RunE: func(cmd *cobra.Command, args []string) error {
Path, configFile, _ = util.InitConfig(Path, configFile)
vaultPath := Path
// Check if the vault exists
vaultExists, err := util.Exists(vaultPath)
if err != nil {
return fmt.Errorf(constants.ErrVaultExistence, err)
}
if !vaultExists {
return fmt.Errorf(constants.ErrVaultDoesNotExist, vaultPath)
}
var action bool
if !Force {
action, err = util.ConfirmAction()
if err != nil {
return fmt.Errorf(constants.ErrActionConfirm, err)
}
} else {
action = true
}
if action {
err = util.RemoveDirectory(vaultPath)
if err != nil {
return fmt.Errorf("failed to remove vault: %w", err)
}
fmt.Printf("Successfully removed vault at %s", vaultPath)
}
return nil
},
}
func init() {
VaultCmd.AddCommand(removeCmd)
}