@@ -25,43 +25,31 @@ import (
2525 "github.com/arduino/arduino-cli/cli/output"
2626 "github.com/arduino/arduino-cli/commands"
2727 rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
28+ "github.com/sirupsen/logrus"
2829 "github.com/spf13/cobra"
2930)
3031
3132func initUpdateIndexCommand () * cobra.Command {
32- return & cobra.Command {
33+ updateIndexCommand := & cobra.Command {
3334 Use : "update-index" ,
3435 Short : tr ("Updates the libraries index." ),
3536 Long : tr ("Updates the libraries index to the latest version." ),
3637 Example : " " + os .Args [0 ] + " lib update-index" ,
3738 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+ }
4843
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 ()
5747
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 )
6654 }
6755}
0 commit comments