@@ -21,59 +21,65 @@ import (
21
21
"fmt"
22
22
"sort"
23
23
24
- "github.com/arduino/arduino-cli/arduino/cores"
25
24
"github.com/gosuri/uitable"
26
25
semver "go.bug.st/relaxed-semver"
27
26
)
28
27
29
- // InstalledPlatformReleases represents an output set of installed platforms.
30
- type InstalledPlatformReleases []* cores.PlatformRelease
31
-
32
- func (is InstalledPlatformReleases ) Len () int { return len (is ) }
33
- func (is InstalledPlatformReleases ) Swap (i , j int ) { is [i ], is [j ] = is [j ], is [i ] }
34
- func (is InstalledPlatformReleases ) Less (i , j int ) bool {
35
- return is [i ].Platform .String () < is [j ].Platform .String ()
28
+ // InstalledPlatforms represents an output of a set of installed platforms.
29
+ type InstalledPlatforms struct {
30
+ Platforms []* InstalledPlatform
36
31
}
37
32
38
- // PlatformReleases represents an output set of tools of platforms.
39
- type PlatformReleases []* cores.PlatformRelease
33
+ // InstalledPlatform represents an output of an installed plaform.
34
+ type InstalledPlatform struct {
35
+ ID string
36
+ Installed * semver.Version
37
+ Latest * semver.Version
38
+ Name string
39
+ }
40
40
41
- func (is PlatformReleases ) Len () int { return len (is ) }
42
- func (is PlatformReleases ) Swap (i , j int ) { is [i ], is [j ] = is [j ], is [i ] }
43
- func (is PlatformReleases ) Less (i , j int ) bool {
44
- return is [i ].Platform .String () < is [j ].Platform .String ()
41
+ func (is InstalledPlatforms ) less (i , j int ) bool {
42
+ return is .Platforms [i ].ID < is .Platforms [j ].ID
45
43
}
46
44
47
- func (is InstalledPlatformReleases ) String () string {
45
+ func (is InstalledPlatforms ) String () string {
48
46
table := uitable .New ()
49
47
table .MaxColWidth = 100
50
48
table .Wrap = true
51
49
52
50
table .AddRow ("ID" , "Installed" , "Latest" , "Name" )
53
- sort .Sort (is )
54
- for _ , item := range is {
55
- var latestVersion * semver.Version
56
- if latest := item .Platform .GetLatestRelease (); latest != nil {
57
- latestVersion = latest .Version
58
- }
59
- table .AddRow (item .Platform , item .Version , latestVersion , item .Platform .Name )
51
+ sort .Slice (is .Platforms , is .less )
52
+ for _ , item := range is .Platforms {
53
+ table .AddRow (item .ID , item .Installed , item .Latest , item .Name )
60
54
}
61
55
return fmt .Sprintln (table )
62
56
}
63
57
64
- func (is PlatformReleases ) String () string {
58
+ // SearchedPlatforms represents an output of a set of searched platforms
59
+ type SearchedPlatforms struct {
60
+ Platforms []* SearchedPlatform
61
+ }
62
+
63
+ func (is SearchedPlatforms ) less (i , j int ) bool {
64
+ return is .Platforms [i ].ID < is .Platforms [j ].ID
65
+ }
66
+
67
+ // SearchedPlatform represents an output of a searched platform
68
+ type SearchedPlatform struct {
69
+ ID string
70
+ Version * semver.Version
71
+ Name string
72
+ }
73
+
74
+ func (is SearchedPlatforms ) String () string {
65
75
table := uitable .New ()
66
76
table .MaxColWidth = 100
67
77
table .Wrap = true
68
78
69
- table .AddRow ("ID" , "Version" , "Installed" , "Name" )
70
- sort .Sort (is )
71
- for _ , item := range is {
72
- installed := "No"
73
- if item .InstallDir != nil {
74
- installed = "Yes"
75
- }
76
- table .AddRow (item .Platform .String (), item .Version , installed , item .Platform .Name )
79
+ sort .Slice (is .Platforms , is .less )
80
+ table .AddRow ("ID" , "Version" , "Name" )
81
+ for _ , item := range is .Platforms {
82
+ table .AddRow (item .ID , item .Version , item .Name )
77
83
}
78
84
return fmt .Sprintln (table )
79
85
}
0 commit comments