-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.go
50 lines (40 loc) · 847 Bytes
/
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
package cmd
import (
"sort"
"github.com/ohsawa0515/akm/config"
"github.com/ohsawa0515/akm/credentials"
"github.com/spf13/cobra"
)
func NewCmdList() *cobra.Command {
cmd := &cobra.Command{
Use: "list",
Aliases: []string{"ls", "l"},
Short: "List all AWS credentials profile.",
RunE: listAction,
}
return cmd
}
func init() {}
func listAction(cmd *cobra.Command, args []string) error {
ac, err := credentials.NewAwsCredentials()
if err != nil {
return err
}
akmConfig, err := config.NewAkmConfig()
if err != nil {
return err
}
var profiles []string
for p := range ac {
profiles = append(profiles, p)
}
sort.Strings(profiles)
for _, profile := range profiles {
if profile == akmConfig.Current {
cmd.Printf("%s (Current)\n", profile)
} else {
cmd.Printf("%s\n", profile)
}
}
return nil
}