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
}

0 commit comments

Comments
 (0)