-
Notifications
You must be signed in to change notification settings - Fork 1
/
listcmd.go
42 lines (38 loc) · 1.09 KB
/
listcmd.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
package configcmd
import (
"fmt"
"github.com/aztekas/cleura-client-go/cmd/cleura/common"
"github.com/aztekas/cleura-client-go/internal/configfile"
"github.com/urfave/cli/v2"
)
func listCommand() *cli.Command {
return &cli.Command{
Name: "list",
Description: "List available configurations",
Usage: "List available configurations defined in configuration file",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "config-path",
Aliases: []string{"p"},
Usage: "Path to configuration file. $HOME/.config/cleura/config if not set",
},
},
Action: func(ctx *cli.Context) error {
logger := common.CliLogger(ctx.String("loglevel"))
logger.Debug("cleura config list")
var config *configfile.Configuration
config, err := configfile.InitConfiguration(ctx.String("config-path"))
if err != nil {
return err
}
fmt.Printf("Available profiles: (in %s)\n", config.Location)
for i, prof := range config.ProfilesSlice() {
if prof == config.GetActiveProfile() {
prof += " (active)"
}
fmt.Printf("%d. %s\n", i, prof)
}
return nil
},
}
}