-
Notifications
You must be signed in to change notification settings - Fork 90
/
frecency.go
58 lines (51 loc) · 1.23 KB
/
frecency.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
51
52
53
54
55
56
57
58
package settings
import (
"fmt"
"os"
"github.com/AlecAivazis/survey/v2"
"github.com/common-fate/clio"
"github.com/common-fate/granted/pkg/config"
"github.com/common-fate/granted/pkg/testable"
"github.com/urfave/cli/v2"
)
var ProfileOrderingCommand = cli.Command{
Name: "profile-order",
Usage: "Update profile ordering when assuming",
Subcommands: []*cli.Command{&SetProfileOrderingCommand},
Action: func(c *cli.Context) error {
cfg, err := config.Load()
if err != nil {
return err
}
fmt.Println(cfg.Ordering)
return nil
},
}
var SetProfileOrderingCommand = cli.Command{
Name: "set",
Usage: "Sets the method of ordering IAM profiles in the assume method",
Action: func(c *cli.Context) error {
cfg, err := config.Load()
if err != nil {
return err
}
withStdio := survey.WithStdio(os.Stdin, os.Stderr, os.Stderr)
in := survey.Select{
Message: "Select filter type",
Options: []string{"Frecency", "Alphabetical"},
}
var selection string
clio.NewLine()
err = testable.AskOne(&in, &selection, withStdio)
if err != nil {
return err
}
cfg.Ordering = selection
err = cfg.Save()
if err != nil {
return err
}
clio.Success("Set profile ordering to: ", selection)
return nil
},
}