@@ -6,7 +6,6 @@ package preflight
6
6
import (
7
7
"context"
8
8
"fmt"
9
- "strconv"
10
9
"strings"
11
10
12
11
"github.com/spf13/pflag"
@@ -31,16 +30,18 @@ func NewRegistry(checks map[string]Check) *Registry {
31
30
}
32
31
33
32
// String returns a string representation of the
34
- // preflight checks. It follows the format:
35
- // CheckName={true||false} ,...
33
+ // enabled preflight checks. It follows the format:
34
+ // CheckName,...
36
35
// This method is needed so Registry implements
37
36
// the pflag.Value interface
38
37
func (c * Registry ) String () string {
39
- defaults := []string {}
38
+ enabled := []string {}
40
39
for k , v := range c .known {
41
- defaults = append (defaults , fmt .Sprintf ("%s=%v" , k , v .Enabled ()))
40
+ if v .Enabled () {
41
+ enabled = append (enabled , k )
42
+ }
42
43
}
43
- return strings .Join (defaults , "," )
44
+ return strings .Join (enabled , "," )
44
45
}
45
46
46
47
// Type returns a string representing the type
@@ -51,33 +52,32 @@ func (c *Registry) Type() string {
51
52
}
52
53
53
54
// Set takes in a string in the format of
54
- // CheckName={true||false} ,...
55
+ // CheckName,...
55
56
// and sets the specified preflight check
56
- // as enabled if true, disabled if false
57
+ // as enabled if listed, otherwise, sets as
58
+ // disabled if not listed.
57
59
// Returns an error if there is a problem
58
60
// parsing the preflight checks
59
61
func (c * Registry ) Set (s string ) error {
60
62
if c .known == nil {
61
63
return nil
62
64
}
63
65
66
+ enabled := map [string ]struct {}{}
67
+ // enable those specified
64
68
mappings := strings .Split (s , "," )
65
- for _ , mapping := range mappings {
66
- set := strings .SplitN (mapping , "=" , 2 )
67
- if len (set ) != 2 {
68
- return fmt .Errorf ("unable to parse check definition %q, too many '='. Must follow the format check={true||false}" , mapping )
69
- }
70
- key , value := set [0 ], set [1 ]
71
-
69
+ for _ , key := range mappings {
72
70
if _ , ok := c .known [key ]; ! ok {
73
71
return fmt .Errorf ("unknown preflight check %q specified" , key )
74
72
}
75
-
76
- enabled , err := strconv .ParseBool (value )
77
- if err != nil {
78
- return fmt .Errorf ("unable to parse boolean representation of %q: %w" , mapping , err )
73
+ c .known [key ].SetEnabled (true )
74
+ enabled [key ] = struct {}{}
75
+ }
76
+ // disable unspecified validators
77
+ for key := range c .known {
78
+ if _ , ok := enabled [key ]; ! ok {
79
+ c .known [key ].SetEnabled (false )
79
80
}
80
- c .known [key ].SetEnabled (enabled )
81
81
}
82
82
return nil
83
83
}
0 commit comments