Skip to content

Commit 31f95fc

Browse files
committed
Propagate context everywhere
1 parent 1775552 commit 31f95fc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+473
-245
lines changed

arduino/commander.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@
1818
package arduino
1919

2020
import (
21+
"context"
22+
2123
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
2224
)
2325

2426
// Commander of arduino package allows to call
2527
// the arduino-cli commands in a programmatic way.
2628
type Commander interface {
27-
BoardList() ([]*rpc.DetectedPort, error)
28-
UploadBin(fqbn, bin, address, protocol string) error
29+
BoardList(ctx context.Context) ([]*rpc.DetectedPort, error)
30+
UploadBin(ctx context.Context, fqbn, bin, address, protocol string) error
2931
//Compile() error
3032
}

arduino/grpc/board.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type boardHandler struct {
3030

3131
// BoardList executes the 'arduino-cli board list' command
3232
// and returns its result.
33-
func (b boardHandler) BoardList() ([]*rpc.DetectedPort, error) {
33+
func (b boardHandler) BoardList(ctx context.Context) ([]*rpc.DetectedPort, error) {
3434
boardListResp, err := b.serviceClient.BoardList(context.Background(),
3535
&rpc.BoardListRequest{Instance: b.instance})
3636

arduino/grpc/compile.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func (c compileHandler) Compile() error {
3838

3939
// Upload executes the 'arduino-cli upload -i' command
4040
// and returns its result.
41-
func (c compileHandler) UploadBin(fqbn, bin, address, protocol string) error {
41+
func (c compileHandler) UploadBin(ctx context.Context, fqbn, bin, address, protocol string) error {
4242
stream, err := c.serviceClient.Upload(context.Background(),
4343
&rpc.UploadRequest{
4444
Instance: c.instance,

cli/dashboard/create.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package dashboard
1919

2020
import (
21+
"context"
2122
"fmt"
2223
"os"
2324
"strings"
@@ -76,7 +77,7 @@ func runCreateCommand(flags *createFlags) error {
7677
params.Name = &flags.name
7778
}
7879

79-
dashboard, err := dashboard.Create(params, cred)
80+
dashboard, err := dashboard.Create(context.TODO(), params, cred)
8081
if err != nil {
8182
return err
8283
}

cli/dashboard/delete.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package dashboard
1919

2020
import (
21+
"context"
2122
"fmt"
2223
"os"
2324

@@ -60,7 +61,7 @@ func runDeleteCommand(flags *deleteFlags) error {
6061
}
6162

6263
params := &dashboard.DeleteParams{ID: flags.id}
63-
err = dashboard.Delete(params, cred)
64+
err = dashboard.Delete(context.TODO(), params, cred)
6465
if err != nil {
6566
return err
6667
}

cli/dashboard/extract.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package dashboard
1919

2020
import (
21+
"context"
2122
"fmt"
2223
"os"
2324

@@ -64,7 +65,7 @@ func runExtractCommand(flags *extractFlags) error {
6465
ID: flags.id,
6566
}
6667

67-
template, err := dashboard.Extract(params, cred)
68+
template, err := dashboard.Extract(context.TODO(), params, cred)
6869
if err != nil {
6970
return err
7071
}

cli/dashboard/list.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package dashboard
1919

2020
import (
21+
"context"
2122
"fmt"
2223
"math"
2324
"os"
@@ -66,7 +67,7 @@ func runListCommand(flags *listFlags) error {
6667
return fmt.Errorf("retrieving credentials: %w", err)
6768
}
6869

69-
dash, err := dashboard.List(cred)
70+
dash, err := dashboard.List(context.TODO(), cred)
7071
if err != nil {
7172
return err
7273
}

cli/device/create.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@
1818
package device
1919

2020
import (
21+
"context"
2122
"fmt"
2223
"os"
24+
"os/signal"
25+
"syscall"
2326

2427
"github.com/arduino/arduino-cli/cli/errorcodes"
2528
"github.com/arduino/arduino-cli/cli/feedback"
@@ -73,7 +76,15 @@ func runCreateCommand(flags *createFlags) error {
7376
params.FQBN = &flags.fqbn
7477
}
7578

76-
dev, err := device.Create(params, cred)
79+
ctx, canc := context.WithCancel(context.Background())
80+
ch := make(chan os.Signal)
81+
signal.Notify(ch, os.Interrupt, syscall.SIGTERM)
82+
go func() {
83+
<-ch
84+
canc()
85+
}()
86+
87+
dev, err := device.Create(ctx, params, cred)
7788
if err != nil {
7889
return err
7990
}

cli/device/creategeneric.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@
1818
package device
1919

2020
import (
21+
"context"
2122
"fmt"
2223
"os"
24+
"os/signal"
25+
"syscall"
2326

2427
"github.com/arduino/arduino-cli/cli/errorcodes"
2528
"github.com/arduino/arduino-cli/cli/feedback"
@@ -66,7 +69,15 @@ func runCreateGenericCommand(flags *createGenericFlags) error {
6669
FQBN: flags.fqbn,
6770
}
6871

69-
dev, err := device.CreateGeneric(params, cred)
72+
ctx, canc := context.WithCancel(context.Background())
73+
ch := make(chan os.Signal)
74+
signal.Notify(ch, os.Interrupt, syscall.SIGTERM)
75+
go func() {
76+
<-ch
77+
canc()
78+
}()
79+
80+
dev, err := device.CreateGeneric(ctx, params, cred)
7081
if err != nil {
7182
return err
7283
}

cli/device/createlora.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@
1818
package device
1919

2020
import (
21+
"context"
2122
"fmt"
2223
"os"
24+
"os/signal"
25+
"syscall"
2326

2427
"github.com/arduino/arduino-cli/cli/errorcodes"
2528
"github.com/arduino/arduino-cli/cli/feedback"
@@ -80,7 +83,15 @@ func runCreateLoraCommand(flags *createLoraFlags) error {
8083
params.FQBN = &flags.fqbn
8184
}
8285

83-
dev, err := device.CreateLora(params, cred)
86+
ctx, canc := context.WithCancel(context.Background())
87+
ch := make(chan os.Signal)
88+
signal.Notify(ch, os.Interrupt, syscall.SIGTERM)
89+
go func() {
90+
<-ch
91+
canc()
92+
}()
93+
94+
dev, err := device.CreateLora(ctx, params, cred)
8495
if err != nil {
8596
return err
8697
}

cli/device/delete.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package device
1919

2020
import (
21+
"context"
2122
"fmt"
2223
"os"
2324

@@ -72,7 +73,7 @@ func runDeleteCommand(flags *deleteFlags) error {
7273
params.ID = &flags.id
7374
}
7475

75-
err = device.Delete(params, cred)
76+
err = device.Delete(context.TODO(), params, cred)
7677
if err != nil {
7778
return err
7879
}

cli/device/list.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package device
1919

2020
import (
21+
"context"
2122
"fmt"
2223
"os"
2324
"strings"
@@ -67,7 +68,7 @@ func runListCommand(flags *listFlags) error {
6768
}
6869

6970
params := &device.ListParams{Tags: flags.tags}
70-
devs, err := device.List(params, cred)
71+
devs, err := device.List(context.TODO(), params, cred)
7172
if err != nil {
7273
return err
7374
}

cli/device/listfqbn.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package device
1919

2020
import (
21+
"context"
2122
"os"
2223

2324
"github.com/arduino/arduino-cli/cli/errorcodes"
@@ -46,7 +47,7 @@ func initListFQBNCommand() *cobra.Command {
4647
func runListFQBNCommand() error {
4748
logrus.Info("Listing supported FQBN")
4849

49-
fqbn, err := device.ListFQBN()
50+
fqbn, err := device.ListFQBN(context.TODO())
5051
if err != nil {
5152
return err
5253
}

cli/device/listfrequency.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package device
1919

2020
import (
21+
"context"
2122
"fmt"
2223
"os"
2324

@@ -53,7 +54,7 @@ func runListFrequencyPlansCommand() error {
5354
return fmt.Errorf("retrieving credentials: %w", err)
5455
}
5556

56-
freqs, err := device.ListFrequencyPlans(cred)
57+
freqs, err := device.ListFrequencyPlans(context.TODO(), cred)
5758
if err != nil {
5859
return err
5960
}

cli/device/tag/create.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package tag
1919

2020
import (
21+
"context"
2122
"fmt"
2223
"os"
2324

@@ -73,7 +74,7 @@ func runCreateTagsCommand(flags *createTagsFlags) error {
7374
return fmt.Errorf("retrieving credentials: %w", err)
7475
}
7576

76-
if err = tag.CreateTags(params, cred); err != nil {
77+
if err = tag.CreateTags(context.TODO(), params, cred); err != nil {
7778
return err
7879
}
7980

cli/device/tag/delete.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package tag
1919

2020
import (
21+
"context"
2122
"fmt"
2223
"os"
2324

@@ -68,7 +69,7 @@ func runDeleteTagsCommand(flags *deleteTagsFlags) error {
6869
Resource: tag.Device,
6970
}
7071

71-
err = tag.DeleteTags(params, cred)
72+
err = tag.DeleteTags(context.TODO(), params, cred)
7273
if err != nil {
7374
return err
7475
}

cli/ota/massupload.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package ota
1919

2020
import (
21+
"context"
2122
"fmt"
2223
"os"
2324
"sort"
@@ -84,7 +85,7 @@ func runMassUploadCommand(flags *massUploadFlags) error {
8485
return fmt.Errorf("retrieving credentials: %w", err)
8586
}
8687

87-
resp, err := ota.MassUpload(params, cred)
88+
resp, err := ota.MassUpload(context.TODO(), params, cred)
8889
if err != nil {
8990
return err
9091
}

cli/ota/upload.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package ota
1919

2020
import (
21+
"context"
2122
"fmt"
2223
"os"
2324

@@ -69,7 +70,7 @@ func runUploadCommand(flags *uploadFlags) error {
6970
File: flags.file,
7071
Deferred: flags.deferred,
7172
}
72-
err = ota.Upload(params, cred)
73+
err = ota.Upload(context.TODO(), params, cred)
7374
if err != nil {
7475
return err
7576
}

cli/thing/bind.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package thing
1919

2020
import (
21+
"context"
2122
"fmt"
2223
"os"
2324

@@ -66,7 +67,7 @@ func runBindCommand(flags *bindFlags) error {
6667
ID: flags.id,
6768
DeviceID: flags.deviceID,
6869
}
69-
if err = thing.Bind(params, cred); err != nil {
70+
if err = thing.Bind(context.TODO(), params, cred); err != nil {
7071
return err
7172
}
7273

cli/thing/clone.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package thing
1919

2020
import (
21+
"context"
2122
"fmt"
2223
"os"
2324
"strings"
@@ -68,7 +69,7 @@ func runCloneCommand(flags *cloneFlags) error {
6869
CloneID: flags.cloneID,
6970
}
7071

71-
thing, err := thing.Clone(params, cred)
72+
thing, err := thing.Clone(context.TODO(), params, cred)
7273
if err != nil {
7374
return err
7475
}

cli/thing/create.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package thing
1919

2020
import (
21+
"context"
2122
"fmt"
2223
"os"
2324
"strings"
@@ -75,7 +76,7 @@ func runCreateCommand(flags *createFlags) error {
7576
params.Name = &flags.name
7677
}
7778

78-
thing, err := thing.Create(params, cred)
79+
thing, err := thing.Create(context.TODO(), params, cred)
7980
if err != nil {
8081
return err
8182
}

cli/thing/delete.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package thing
1919

2020
import (
21+
"context"
2122
"fmt"
2223
"os"
2324

@@ -72,7 +73,7 @@ func runDeleteCommand(flags *deleteFlags) error {
7273
params.ID = &flags.id
7374
}
7475

75-
err = thing.Delete(params, cred)
76+
err = thing.Delete(context.TODO(), params, cred)
7677
if err != nil {
7778
return err
7879
}

0 commit comments

Comments
 (0)