-
Notifications
You must be signed in to change notification settings - Fork 1
/
list.go
59 lines (52 loc) · 1.17 KB
/
list.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
58
59
package app
import (
"fmt"
"log"
"github.com/urfave/cli"
"github.com/garlsecurity/securepassctl/spctl/service"
)
func init() {
Command.Subcommands = append(Command.Subcommands,
cli.Command{
Name: "list",
Usage: "list SecurePass's applications",
ArgsUsage: " ",
Description: "List SecurePass's applications.",
Action: ActionList,
Flags: []cli.Flag{
cli.StringFlag{
Name: "realm, r",
Usage: "Set alternate realm",
},
cli.BoolFlag{
Name: "details, d",
Usage: "Show more details",
},
},
})
}
// ActionList provides the app list command
func ActionList(c *cli.Context) {
if len(c.Args()) != 0 {
log.Fatal("too many arguments")
}
resp, err := service.Service.AppList(c.String("realm"))
if err != nil {
log.Fatalf("error: %v", err)
}
if c.Bool("details") {
fmt.Printf("%-45s %-30s\n", "APP_ID", "LABEL")
}
for _, app := range resp.AppID {
if !c.Bool("details") {
fmt.Printf("%s\n", app)
} else {
r, e := service.Service.AppInfo(app)
if e != nil {
log.Fatalf("couldn't retrieve details for '%s': %s",
app, err)
}
fmt.Printf("%-45s %-30s\n", app, r.Label)
}
}
}