@@ -22,17 +22,18 @@ import (
22
22
"fmt"
23
23
"io"
24
24
"os/exec"
25
+ "strings"
25
26
"time"
26
27
28
+ "github.com/arduino/arduino-cli/arduino/cores"
27
29
"github.com/arduino/arduino-cli/arduino/cores/packagemanager"
28
-
29
- properties "github.com/arduino/go-properties-orderedmap"
30
-
31
30
"github.com/arduino/arduino-cli/executils"
31
+ properties "github.com/arduino/go-properties-orderedmap"
32
32
)
33
33
34
34
// Discovery is an instance of a discovery tool
35
35
type Discovery struct {
36
+ ID string
36
37
in io.WriteCloser
37
38
out io.ReadCloser
38
39
outJSON * json.Decoder
@@ -60,7 +61,10 @@ func NewFromCommandLine(args ...string) (*Discovery, error) {
60
61
if err != nil {
61
62
return nil , fmt .Errorf ("creating discovery process: %s" , err )
62
63
}
63
- return & Discovery {cmd : cmd }, nil
64
+ return & Discovery {
65
+ ID : strings .Join (args , " " ),
66
+ cmd : cmd ,
67
+ }, nil
64
68
}
65
69
66
70
// Start starts the specified discovery
@@ -124,23 +128,36 @@ func (d *Discovery) Close() error {
124
128
}
125
129
126
130
// ExtractDiscoveriesFromPlatforms returns all Discovery from all the installed platforms.
127
- func ExtractDiscoveriesFromPlatforms (pm * packagemanager.PackageManager ) map [ string ]* Discovery {
128
- res := map [ string ]* Discovery {}
129
-
131
+ func ExtractDiscoveriesFromPlatforms (pm * packagemanager.PackageManager ) [ ]* Discovery {
132
+ res := [ ]* Discovery {}
133
+ taken := map [ string ] bool {}
130
134
for _ , platformRelease := range pm .InstalledPlatformReleases () {
131
- discoveries := platformRelease .Properties .SubTree ("discovery" ).FirstLevelOf ()
135
+ for _ , disc := range ExtractDiscoveriesFromPlatform (platformRelease ) {
136
+ if taken [disc .ID ] {
137
+ continue
138
+ }
139
+ taken [disc .ID ] = true
140
+ res = append (res , disc )
141
+ }
142
+ }
143
+ return res
144
+ }
132
145
133
- for name , props := range discoveries {
134
- if pattern , has := props .GetOk ("pattern" ); has {
135
- props .Merge (platformRelease .Properties )
136
- cmdLine := props .ExpandPropsInString (pattern )
137
- if cmdArgs , err := properties .SplitQuotedString (cmdLine , `"` , false ); err != nil {
138
- // TODO
139
- } else if disc , err := NewFromCommandLine (cmdArgs ... ); err != nil {
140
- // TODO
141
- } else {
142
- res [name ] = disc
143
- }
146
+ // ExtractDiscoveriesFromPlatform returns all Discovery from the specified platform.
147
+ func ExtractDiscoveriesFromPlatform (platformRelease * cores.PlatformRelease ) []* Discovery {
148
+ discoveries := platformRelease .Properties .SubTree ("discovery" ).FirstLevelOf ()
149
+
150
+ res := []* Discovery {}
151
+ for _ , props := range discoveries {
152
+ if pattern , has := props .GetOk ("pattern" ); has {
153
+ props .Merge (platformRelease .Properties )
154
+ cmdLine := props .ExpandPropsInString (pattern )
155
+ if cmdArgs , err := properties .SplitQuotedString (cmdLine , `"` , false ); err != nil {
156
+ // TODO
157
+ } else if disc , err := NewFromCommandLine (cmdArgs ... ); err != nil {
158
+ // TODO
159
+ } else {
160
+ res = append (res , disc )
144
161
}
145
162
}
146
163
}
0 commit comments