-
Notifications
You must be signed in to change notification settings - Fork 2
/
cmdremove.go
46 lines (40 loc) · 871 Bytes
/
cmdremove.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
package main
import "fmt"
func init() {
registerSubcommand(&Subcommand{
Name: "remove",
Aliases: []string{"rm"},
Usage: "<website> [username]",
Hint: "Remove specific record from storage.",
Handler: cmdRemove,
})
}
func cmdRemove(args []string) bool {
rem, stg, masterpwd, ok := openAndFindRecord(args)
if !ok {
return false
}
var ans string
printRecord(rem)
fmt.Println("Are you sure you want to delete this record?")
fmt.Println("This action cannot be rolled back.")
fmt.Print("(y/N): ")
fmt.Scanln(&ans)
if ans != "y" && ans != "Y" {
fmt.Println("Deletion has been canceled.")
return true
}
var ind = -1
for i := range stg {
if stg[i] == rem {
ind = i
break
}
}
stg = append(stg[:ind], stg[ind+1:]...)
if !saveStorage(stg, masterpwd) {
return false
}
fmt.Println("Record has been deleted.")
return true
}