@@ -32,12 +32,9 @@ import (
32
32
"github.com/spf13/cobra"
33
33
)
34
34
35
- var (
36
- all bool
37
- updatable bool
38
- )
39
-
40
35
func initListCommand () * cobra.Command {
36
+ var all bool
37
+ var updatable bool
41
38
listCommand := & cobra.Command {
42
39
Use : fmt .Sprintf ("list [%s]" , tr ("LIBNAME" )),
43
40
Short : tr ("Shows a list of installed libraries." ),
@@ -48,15 +45,17 @@ library. By default the libraries provided as built-in by platforms/core are
48
45
not listed, they can be listed by adding the --all flag.` ),
49
46
Example : " " + os .Args [0 ] + " lib list" ,
50
47
Args : cobra .MaximumNArgs (1 ),
51
- Run : runListCommand ,
48
+ Run : func (cmd * cobra.Command , args []string ) {
49
+ runListCommand (args , all , updatable )
50
+ },
52
51
}
53
52
listCommand .Flags ().BoolVar (& all , "all" , false , tr ("Include built-in libraries (from platforms and IDE) in listing." ))
54
53
fqbn .AddToCommand (listCommand )
55
54
listCommand .Flags ().BoolVar (& updatable , "updatable" , false , tr ("List updatable libraries." ))
56
55
return listCommand
57
56
}
58
57
59
- func runListCommand (cmd * cobra. Command , args []string ) {
58
+ func runListCommand (args []string , all bool , updatable bool ) {
60
59
instance := instance .CreateAndInit ()
61
60
logrus .Info ("Executing `arduino-cli lib list`" )
62
61
@@ -94,13 +93,17 @@ func runListCommand(cmd *cobra.Command, args []string) {
94
93
libs = []* rpc.InstalledLibrary {}
95
94
}
96
95
97
- feedback .PrintResult (installedResult {libs })
96
+ feedback .PrintResult (installedResult {
97
+ onlyUpdates : updatable ,
98
+ installedLibs : libs ,
99
+ })
98
100
logrus .Info ("Done" )
99
101
}
100
102
101
103
// output from this command requires special formatting, let's create a dedicated
102
104
// feedback.Result implementation
103
105
type installedResult struct {
106
+ onlyUpdates bool
104
107
installedLibs []* rpc.InstalledLibrary
105
108
}
106
109
@@ -109,9 +112,9 @@ func (ir installedResult) Data() interface{} {
109
112
}
110
113
111
114
func (ir installedResult ) String () string {
112
- if ir . installedLibs == nil || len (ir .installedLibs ) == 0 {
113
- if updatable {
114
- return tr ("No updates available." )
115
+ if len (ir .installedLibs ) == 0 {
116
+ if ir . onlyUpdates {
117
+ return tr ("No libraries update is available." )
115
118
}
116
119
return tr ("No libraries installed." )
117
120
}
0 commit comments