Skip to content

Commit 5a09c2c

Browse files
committed
Factored FQBN.SetConfig method
it will be used in next commits
1 parent 2ed118b commit 5a09c2c

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

arduino/cores/fqbn.go

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,22 +48,31 @@ func ParseFQBN(fqbnIn string) (*FQBN, error) {
4848
return nil, fmt.Errorf("invalid fqbn: empty board identifier")
4949
}
5050
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
6253
}
6354
}
6455
return fqbn, nil
6556
}
6657

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+
6776
// MustParseFQBN extract an FQBN object from the input string or panics
6877
// if there is an error parsing the FQBN
6978
func MustParseFQBN(fqbnIn string) *FQBN {

0 commit comments

Comments
 (0)