forked from 99designs/aws-vault
/
ls.go
41 lines (33 loc) · 737 Bytes
/
ls.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
package cli
import (
"fmt"
"github.com/99designs/keyring"
"gopkg.in/alecthomas/kingpin.v2"
)
type LsCommandInput struct {
Keyring keyring.Keyring
}
func ConfigureListCommand(app *kingpin.Application) {
input := LsCommandInput{}
cmd := app.Command("list", "List all credentials and sessions")
cmd.Alias("ls")
cmd.Action(func(c *kingpin.ParseContext) error {
input.Keyring = keyringImpl
LsCommand(app, input)
return nil
})
}
func LsCommand(app *kingpin.Application, input LsCommandInput) {
accounts, err := input.Keyring.Keys()
if err != nil {
app.Fatalf(err.Error())
return
}
for _, name := range accounts {
fmt.Println(name)
}
if len(accounts) == 0 {
app.Fatalf("No credentials found")
return
}
}