-
Notifications
You must be signed in to change notification settings - Fork 4
/
filter.go
57 lines (44 loc) · 1.19 KB
/
filter.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
package main
import (
"fmt"
"strings"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/rds"
"gopkg.in/alecthomas/kingpin.v2"
)
type rdsFiltersValue []*rds.Filter
func (r *rdsFiltersValue) Set(value string) error {
parts := strings.SplitN(value, ",", 2)
if len(parts) != 2 {
return fmt.Errorf("expected Name=NAME,Values=VALUES got '%s'", value)
}
nargs := strings.SplitN(parts[0], "=", 2)
if len(nargs) != 2 && nargs[0] != "Name" {
return fmt.Errorf("expected Name=NAME,Values=VALUES got '%s'", value)
}
vargs := strings.SplitN(parts[1], "=", 2)
if len(vargs) != 2 && vargs[0] != "Values" {
return fmt.Errorf("expected Name=NAME,Values=VALUES got '%s'", value)
}
values := strings.Split(vargs[1], ",")
filter := rds.Filter{
Name: aws.String(nargs[1]),
Values: make([]*string, len(values)),
}
for i, v := range values {
filter.Values[i] = aws.String(v)
}
*r = append(*r, &filter)
return nil
}
func (r *rdsFiltersValue) String() string {
return ""
}
func (r *rdsFiltersValue) IsCumulative() bool {
return true
}
func rdsFilters(s kingpin.Settings) (target *[]*rds.Filter) {
target = &[]*rds.Filter{}
s.SetValue((*rdsFiltersValue)(target))
return
}