/
del.go
57 lines (45 loc) · 1.01 KB
/
del.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
56
57
package group
import (
"fmt"
"log"
"os"
"strings"
"github.com/urfave/cli"
"github.com/garlsecurity/securepassctl/spctl/service"
)
func init() {
Command.Subcommands = append(Command.Subcommands,
cli.Command{
Name: "del",
Usage: "delete group",
ArgsUsage: "GROUP",
Description: "Delete a group from SecurePass.",
Action: ActionDel,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "yes, y",
Usage: "Skip confirmation",
},
},
})
}
// ActionDel provides the del subcommand
func ActionDel(c *cli.Context) {
if len(c.Args()) != 1 {
log.Fatal("error: must specify a group")
}
group := c.Args()[0]
if !c.Bool("yes") {
var reply string
fmt.Fprintf(os.Stderr, "Do you want to delete the group %q? [y/N] ", group)
fmt.Scanln(&reply)
reply = strings.ToLower(reply)
if reply != "y" && reply != "yes" {
os.Exit(-1)
}
}
if _, err := service.Service.GroupDel(group); err != nil {
log.Fatalf("error: %v", err)
}
log.Printf("Group deleted: %s", group)
}