Skip to content

Commit eadda13

Browse files
committed
Fix instance creation for CLI commands that update indexes
1 parent 4417fdd commit eadda13

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

cli/core/update_index.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,16 @@ func initUpdateIndexCommand() *cobra.Command {
4242
}
4343

4444
func runUpdateIndexCommand(cmd *cobra.Command, args []string) {
45-
instance := instance.CreateAndInit()
4645
logrus.Info("Executing `arduino core update-index`")
46+
// We don't initialize any CoreInstance when updating indexes since we don't need to.
47+
// Also meaningless errors might be returned when calling this command with --additional-urls
48+
// since the CLI would be searching for a corresponding file for the additional urls set
49+
// as argument but none would be obviously found.
50+
instance, status := instance.Create()
51+
if status != nil {
52+
feedback.Errorf("Error creating instance: %v", status)
53+
os.Exit(errorcodes.ErrGeneric)
54+
}
4755

4856
_, err := commands.UpdateIndex(context.Background(), &rpc.UpdateIndexRequest{
4957
Instance: instance,

cli/lib/update_index.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,15 @@ func initUpdateIndexCommand() *cobra.Command {
3636
Example: " " + os.Args[0] + " lib update-index",
3737
Args: cobra.NoArgs,
3838
Run: func(cmd *cobra.Command, args []string) {
39-
instance := instance.CreateAndInit()
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+
instance, status := instance.Create()
44+
if status != nil {
45+
feedback.Errorf("Error creating instance: %v", status)
46+
os.Exit(errorcodes.ErrGeneric)
47+
}
4048
err := commands.UpdateLibrariesIndex(context.Background(), &rpc.UpdateLibrariesIndexRequest{
4149
Instance: instance,
4250
}, output.ProgressBar())

cli/update/update.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,15 @@ var updateFlags struct {
4949
}
5050

5151
func runUpdateCommand(cmd *cobra.Command, args []string) {
52-
instance := instance.CreateAndInit()
53-
52+
// We don't initialize any CoreInstance when updating indexes since we don't need to.
53+
// Also meaningless errors might be returned when calling this command with --additional-urls
54+
// since the CLI would be searching for a corresponding file for the additional urls set
55+
// as argument but none would be obviously found.
56+
instance, status := instance.Create()
57+
if status != nil {
58+
feedback.Errorf("Error creating instance: %v", status)
59+
os.Exit(errorcodes.ErrGeneric)
60+
}
5461
logrus.Info("Executing `arduino update`")
5562

5663
err := commands.UpdateCoreLibrariesIndex(context.Background(), &rpc.UpdateCoreLibrariesIndexRequest{

0 commit comments

Comments
 (0)