@@ -18,11 +18,12 @@ package kepctl
18
18
19
19
import (
20
20
"fmt"
21
- "strings "
21
+ "regexp "
22
22
23
23
"github.com/pkg/errors"
24
24
25
25
"k8s.io/enhancements/pkg/kepval/keps"
26
+ "k8s.io/enhancements/pkg/kepval/keps/validations"
26
27
)
27
28
28
29
type QueryOpts struct {
@@ -36,15 +37,14 @@ type QueryOpts struct {
36
37
// Validate checks the args and cleans them up if needed
37
38
func (c * QueryOpts ) Validate (args []string ) error {
38
39
if len (c .SIG ) > 0 {
39
- var fixed []string
40
- for _ , s := range c .SIG {
41
- if strings .HasPrefix (s , "sig-" ) {
42
- fixed = append (fixed , s )
43
- } else {
44
- fixed = append (fixed , "sig-" + s )
45
- }
40
+ sigs , err := selectByRegexp (validations .Sigs (), c .SIG )
41
+ if err != nil {
42
+ return err
46
43
}
47
- c .SIG = fixed
44
+ if len (sigs ) == 0 {
45
+ return fmt .Errorf ("No SIG matches any of the passed regular expressions" )
46
+ }
47
+ c .SIG = sigs
48
48
}
49
49
//TODO: check the valid values of stage, status, etc.
50
50
return nil
@@ -67,13 +67,13 @@ func (c *Client) Query(opts QueryOpts) error {
67
67
// KEPs in the local filesystem
68
68
names , err := findLocalKEPs (repoPath , sig )
69
69
if err != nil {
70
- return errors . Wrap ( err , "unable to search for local KEPs" )
70
+ fmt . Fprintf ( c . Err , "error searching for local KEPs from %s: %s \n " , sig , err )
71
71
}
72
72
73
73
for _ , k := range names {
74
74
kep , err := c .readKEP (repoPath , sig , k )
75
75
if err != nil {
76
- fmt .Fprintf (c .Err , "ERROR READING KEP %s: %s\n " , k , err )
76
+ fmt .Fprintf (c .Err , "error reading KEP %s: %s\n " , k , err )
77
77
} else {
78
78
allKEPs = append (allKEPs , kep )
79
79
}
@@ -83,7 +83,7 @@ func (c *Client) Query(opts QueryOpts) error {
83
83
if opts .IncludePRs {
84
84
prKeps , err := c .findKEPPullRequests (sig )
85
85
if err != nil {
86
- return errors . Wrap ( err , "unable to search for KEP PRs" )
86
+ fmt . Fprintf ( c . Err , "error searching for KEP PRs from %s: %s \n " , sig , err )
87
87
}
88
88
if prKeps != nil {
89
89
allKEPs = append (allKEPs , prKeps ... )
@@ -117,3 +117,22 @@ func sliceToMap(s []string) map[string]bool {
117
117
}
118
118
return m
119
119
}
120
+
121
+ // returns all strings in vals that match at least one
122
+ // regexp in regexps
123
+ func selectByRegexp (vals []string , regexps []string ) ([]string , error ) {
124
+ var matches []string
125
+ for _ , s := range vals {
126
+ for _ , r := range regexps {
127
+ found , err := regexp .MatchString (r , s )
128
+ if err != nil {
129
+ return matches , err
130
+ }
131
+ if found {
132
+ matches = append (matches , s )
133
+ break
134
+ }
135
+ }
136
+ }
137
+ return matches , nil
138
+ }
0 commit comments