@@ -25,43 +25,31 @@ import (
25
25
"github.com/arduino/arduino-cli/cli/output"
26
26
"github.com/arduino/arduino-cli/commands"
27
27
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
28
+ "github.com/sirupsen/logrus"
28
29
"github.com/spf13/cobra"
29
30
)
30
31
31
32
func initUpdateIndexCommand () * cobra.Command {
32
- return & cobra.Command {
33
+ updateIndexCommand := & cobra.Command {
33
34
Use : "update-index" ,
34
35
Short : tr ("Updates the libraries index." ),
35
36
Long : tr ("Updates the libraries index to the latest version." ),
36
37
Example : " " + os .Args [0 ] + " lib update-index" ,
37
38
Args : cobra .NoArgs ,
38
- Run : func (cmd * cobra.Command , args []string ) {
39
- // We don't initialize any CoreInstance when updating indexes since we don't need to.
40
- // Also meaningless errors might be returned when calling this command with --additional-urls
41
- // since the CLI would be searching for a corresponding file for the additional urls set
42
- // as argument but none would be obviously found.
43
- inst , status := instance .Create ()
44
- if status != nil {
45
- feedback .Errorf (tr ("Error creating instance: %v" ), status )
46
- os .Exit (errorcodes .ErrGeneric )
47
- }
39
+ Run : runUpdateIndexCommand ,
40
+ }
41
+ return updateIndexCommand
42
+ }
48
43
49
- // In case this is the first time the CLI is run we need to update indexes
50
- // to make it work correctly, we must do this explicitly in this command since
51
- // we must use instance.Create instead of instance.CreateAndInit for the
52
- // reason stated above.
53
- if err := instance .FirstUpdate (inst ); err != nil {
54
- feedback .Errorf (tr ("Error updating indexes: %v" ), status )
55
- os .Exit (errorcodes .ErrGeneric )
56
- }
44
+ func runUpdateIndexCommand (cmd * cobra.Command , args []string ) {
45
+ logrus .Info ("Executing `arduino lib update-index`" )
46
+ inst := instance .CreateInstanceAndRunFirstUpdate ()
57
47
58
- err := commands .UpdateLibrariesIndex (context .Background (), & rpc.UpdateLibrariesIndexRequest {
59
- Instance : inst ,
60
- }, output .ProgressBar ())
61
- if err != nil {
62
- feedback .Errorf (tr ("Error updating library index: %v" ), err )
63
- os .Exit (errorcodes .ErrGeneric )
64
- }
65
- },
48
+ err := commands .UpdateLibrariesIndex (context .Background (), & rpc.UpdateLibrariesIndexRequest {
49
+ Instance : inst ,
50
+ }, output .ProgressBar ())
51
+ if err != nil {
52
+ feedback .Errorf (tr ("Error updating library index: %v" ), err )
53
+ os .Exit (errorcodes .ErrGeneric )
66
54
}
67
55
}
0 commit comments