@@ -48,22 +48,31 @@ func ParseFQBN(fqbnIn string) (*FQBN, error) {
48
48
return nil , fmt .Errorf ("invalid fqbn: empty board identifier" )
49
49
}
50
50
if len (fqbnParts ) > 3 {
51
- for _ , pair := range strings .Split (fqbnParts [3 ], "," ) {
52
- parts := strings .SplitN (pair , "=" , 2 )
53
- if len (parts ) != 2 {
54
- return nil , fmt .Errorf ("invalid fqbn config: %s" , pair )
55
- }
56
- k := strings .TrimSpace (parts [0 ])
57
- v := strings .TrimSpace (parts [1 ])
58
- if k == "" {
59
- return nil , fmt .Errorf ("invalid fqbn config: %s" , pair )
60
- }
61
- fqbn .Configs .Set (k , v )
51
+ if err := fqbn .SetConfigs (strings .Split (fqbnParts [3 ], "," )); err != nil {
52
+ return nil , err
62
53
}
63
54
}
64
55
return fqbn , nil
65
56
}
66
57
58
+ // SetConfigs set the configs part of the FQBN with the provided config strings.
59
+ // Each config string must be a pair "config=value".
60
+ func (fqbn * FQBN ) SetConfigs (configs []string ) error {
61
+ for _ , pair := range configs {
62
+ parts := strings .SplitN (pair , "=" , 2 )
63
+ if len (parts ) != 2 {
64
+ return fmt .Errorf ("invalid fqbn config: %s" , pair )
65
+ }
66
+ k := strings .TrimSpace (parts [0 ])
67
+ v := strings .TrimSpace (parts [1 ])
68
+ if k == "" {
69
+ return fmt .Errorf ("invalid fqbn config: %s" , pair )
70
+ }
71
+ fqbn .Configs .Set (k , v )
72
+ }
73
+ return nil
74
+ }
75
+
67
76
// MustParseFQBN extract an FQBN object from the input string or panics
68
77
// if there is an error parsing the FQBN
69
78
func MustParseFQBN (fqbnIn string ) * FQBN {
0 commit comments