/
options.go
62 lines (53 loc) · 1.41 KB
/
options.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
59
60
61
62
package iam_role
import (
"fmt"
"github.com/awslabs/eksdemo/pkg/cmd"
"github.com/awslabs/eksdemo/pkg/resource"
"github.com/spf13/cobra"
)
type IamRoleOptions struct {
resource.CommonOptions
LastUsed bool
NameSearch string
}
func NewOptions() (options *IamRoleOptions, getFlags cmd.Flags) {
options = &IamRoleOptions{
CommonOptions: resource.CommonOptions{
ClusterFlagDisabled: true,
},
}
clusterFlag := options.NewClusterFlag(resource.Get, false)
clusterFlag.Description = "filter by IRSA roles for cluster"
origValidate := clusterFlag.Validate
clusterFlag.Validate = func(cmd *cobra.Command, args []string) error {
if options.ClusterName != "" && len(args) > 0 {
return fmt.Errorf("%q flag cannot be used with NAME argument", "--cluster")
}
return origValidate(cmd, args)
}
getFlags = cmd.Flags{
clusterFlag,
&cmd.BoolFlag{
CommandFlag: cmd.CommandFlag{
Name: "last-used",
Description: "show last used date",
Shorthand: "L",
},
Option: &options.LastUsed,
},
&cmd.StringFlag{
CommandFlag: cmd.CommandFlag{
Name: "search",
Description: "case-insensitive name search",
Validate: func(cmd *cobra.Command, args []string) error {
if options.NameSearch != "" && len(args) > 0 {
return fmt.Errorf("%q flag cannot be used with NAME argument", "search")
}
return nil
},
},
Option: &options.NameSearch,
},
}
return
}