1616package outdated
1717
1818import (
19- "context"
2019 "os"
2120
22- "github.com/arduino/arduino-cli/cli/errorcodes"
23- "github.com/arduino/arduino-cli/cli/feedback"
21+ "github.com/arduino/arduino-cli/cli/core"
2422 "github.com/arduino/arduino-cli/cli/instance"
25- "github.com/arduino/arduino-cli/commands/core"
26- "github.com/arduino/arduino-cli/commands/lib"
23+ "github.com/arduino/arduino-cli/cli/lib"
2724 "github.com/arduino/arduino-cli/i18n"
2825 rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
29- "github.com/arduino/arduino-cli/table"
3026 "github.com/sirupsen/logrus"
3127 "github.com/spf13/cobra"
3228)
@@ -44,57 +40,17 @@ that can be upgraded. If nothing needs to be updated the output is empty.`),
4440 Args : cobra .NoArgs ,
4541 Run : runOutdatedCommand ,
4642 }
47-
4843 return outdatedCommand
4944}
5045
5146func runOutdatedCommand (cmd * cobra.Command , args []string ) {
5247 inst := instance .CreateAndInit ()
5348 logrus .Info ("Executing `arduino-cli outdated`" )
54-
55- outdatedResp , err := outdated .Outdated (context .Background (), & rpc.OutdatedRequest {
56- Instance : inst ,
57- })
58- if err != nil {
59- feedback .Errorf (tr ("Error retrieving outdated cores and libraries: %v" ), err )
60- }
61-
62- feedback .PrintResult (outdatedResult {
63- Platforms : outdatedResp .OutdatedPlatforms ,
64- Libraries : outdatedResp .OutdatedLibraries })
65- }
66-
67- // output from this command requires special formatting, let's create a dedicated
68- // feedback.Result implementation
69- type outdatedResult struct {
70- Platforms []* rpc.Platform
71- Libraries []* rpc.InstalledLibrary
49+ Outdated (inst )
7250}
7351
74- func (or outdatedResult ) Data () interface {} {
75- return or
76- }
77-
78- func (or outdatedResult ) String () string {
79- // Prints outdated cores
80- t1 := table .New ()
81- if len (or .Platforms ) > 0 {
82- t1 .SetHeader (tr ("ID" ), tr ("Installed version" ), tr ("New version" ), tr ("Name" ))
83- for _ , p := range or .Platforms {
84- t1 .AddRow (p .Id , p .Installed , p .Latest , p .Name )
85- }
86- }
87-
88- // Prints outdated libraries
89- t2 := table .New ()
90- if len (or .Libraries ) > 0 {
91- t2 .SetHeader (tr ("Library name" ), tr ("Installed version" ), tr ("New version" ))
92- for _ , l := range or .Libraries {
93- t2 .AddRow (l .Library .Name , l .Library .Version , l .Release .Version )
94- }
95- }
96- if len (or .Libraries ) > 0 && len (or .Platforms ) > 0 {
97- return t1 .Render () + "\n " + t2 .Render () // handle the new line between tables
98- }
99- return t1 .Render () + t2 .Render ()
52+ // Outdated returns a list of outdated platforms and libraries
53+ func Outdated (inst * rpc.Instance ) {
54+ core .List (inst , false , true )
55+ lib .List (inst , []string {}, false , true )
10056}
0 commit comments