-
Notifications
You must be signed in to change notification settings - Fork 1
/
showcmd.go
50 lines (46 loc) · 1.31 KB
/
showcmd.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 configcmd
import (
"fmt"
"github.com/aztekas/cleura-client-go/internal/configfile"
"github.com/urfave/cli/v2"
"golang.org/x/exp/maps"
)
func showCommand() *cli.Command {
return &cli.Command{
Name: "show",
Description: "Show configured settings for given configuration",
Usage: "Show configured settings for given configuration",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "config-path",
Aliases: []string{"p"},
Usage: "Path to configuration file. $HOME/.config/cleura/config if not set",
},
&cli.StringFlag{
Name: "name",
Aliases: []string{"n"},
Usage: "Configuration name within config file. Choose currently active by default",
},
},
Action: func(ctx *cli.Context) error {
var config *configfile.Configuration
config, err := configfile.InitConfiguration(ctx.String("config-path"))
if err != nil {
return err
}
profileMap, err := config.GetProfileMap(ctx.String("name"))
if err != nil {
return err
}
fmt.Printf("Details for profile: `%s`\n", config.GetActiveProfile())
for _, key := range maps.Keys(profileMap) {
if key == "token" && profileMap[key] != "" {
fmt.Printf("%-10s: ****hidden****\n", "token")
} else {
fmt.Printf("%-10s: %s\n", key, profileMap[key])
}
}
return nil
},
}
}