-
Notifications
You must be signed in to change notification settings - Fork 83
/
apikey_list.go
46 lines (37 loc) · 1.04 KB
/
apikey_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
package apikey
import (
"sort"
"github.com/civo/cli/config"
"github.com/civo/cli/utility"
"github.com/spf13/cobra"
)
var apikeyListCmd = &cobra.Command{
Use: "ls",
Aliases: []string{"list", "all"},
Short: "List stored API keys",
Long: `List all API keys, making clear which is the current default.
If you wish to use a custom format, the available fields are:
* name
* key
Example: civo apikey ls -o custom -f "Name: Key"`,
Run: func(cmd *cobra.Command, args []string) {
keys := make([]string, 0, len(config.Current.APIKeys))
for k := range config.Current.APIKeys {
keys = append(keys, k)
}
sort.Strings(keys)
ow := utility.NewOutputWriter()
for _, name := range keys {
ow.StartLine()
// apiKey := config.Current.APIKeys[name]
defaultLabel := ""
if config.Current.Meta.CurrentAPIKey == name {
defaultLabel = "<====="
}
ow.AppendDataWithLabel("name", name, "Name")
// ow.AppendData("Key", apiKey)
ow.AppendDataWithLabel("default", defaultLabel, "Default")
}
ow.FinishAndPrintOutput()
},
}