File tree Expand file tree Collapse file tree 4 files changed +11
-28
lines changed Expand file tree Collapse file tree 4 files changed +11
-28
lines changed Original file line number Diff line number Diff line change @@ -21,15 +21,14 @@ import (
21
21
"context"
22
22
"fmt"
23
23
"os"
24
- "os/signal"
25
- "syscall"
26
24
27
25
"github.com/arduino/arduino-cli/cli/errorcodes"
28
26
"github.com/arduino/arduino-cli/cli/feedback"
29
27
"github.com/arduino/arduino-cloud-cli/command/device"
30
28
"github.com/arduino/arduino-cloud-cli/config"
31
29
"github.com/sirupsen/logrus"
32
30
"github.com/spf13/cobra"
31
+ "go.bug.st/cleanup"
33
32
)
34
33
35
34
type createFlags struct {
@@ -76,13 +75,8 @@ func runCreateCommand(flags *createFlags) error {
76
75
params .FQBN = & flags .fqbn
77
76
}
78
77
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
- }()
78
+ ctx , cancel := cleanup .InterruptableContext (context .Background ())
79
+ defer cancel ()
86
80
87
81
dev , err := device .Create (ctx , params , cred )
88
82
if err != nil {
Original file line number Diff line number Diff line change @@ -21,15 +21,14 @@ import (
21
21
"context"
22
22
"fmt"
23
23
"os"
24
- "os/signal"
25
- "syscall"
26
24
27
25
"github.com/arduino/arduino-cli/cli/errorcodes"
28
26
"github.com/arduino/arduino-cli/cli/feedback"
29
27
"github.com/arduino/arduino-cloud-cli/command/device"
30
28
"github.com/arduino/arduino-cloud-cli/config"
31
29
"github.com/sirupsen/logrus"
32
30
"github.com/spf13/cobra"
31
+ "go.bug.st/cleanup"
33
32
)
34
33
35
34
type createGenericFlags struct {
@@ -69,13 +68,8 @@ func runCreateGenericCommand(flags *createGenericFlags) error {
69
68
FQBN : flags .fqbn ,
70
69
}
71
70
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
- }()
71
+ ctx , cancel := cleanup .InterruptableContext (context .Background ())
72
+ defer cancel ()
79
73
80
74
dev , err := device .CreateGeneric (ctx , params , cred )
81
75
if err != nil {
Original file line number Diff line number Diff line change @@ -21,15 +21,14 @@ import (
21
21
"context"
22
22
"fmt"
23
23
"os"
24
- "os/signal"
25
- "syscall"
26
24
27
25
"github.com/arduino/arduino-cli/cli/errorcodes"
28
26
"github.com/arduino/arduino-cli/cli/feedback"
29
27
"github.com/arduino/arduino-cloud-cli/command/device"
30
28
"github.com/arduino/arduino-cloud-cli/config"
31
29
"github.com/sirupsen/logrus"
32
30
"github.com/spf13/cobra"
31
+ "go.bug.st/cleanup"
33
32
)
34
33
35
34
type createLoraFlags struct {
@@ -83,13 +82,8 @@ func runCreateLoraCommand(flags *createLoraFlags) error {
83
82
params .FQBN = & flags .fqbn
84
83
}
85
84
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
- }()
85
+ ctx , cancel := cleanup .InterruptableContext (context .Background ())
86
+ defer cancel ()
93
87
94
88
dev , err := device .CreateLora (ctx , params , cred )
95
89
if err != nil {
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ require (
15
15
github.com/google/go-cmp v0.5.6
16
16
github.com/h2non/filetype v1.1.3 // indirect
17
17
github.com/howeyc/crc16 v0.0.0-20171223171357-2b2a61e366a6
18
- github.com/juju/errors v0.0.0-20210818161939-5560c4c073ff
18
+ github.com/juju/errors v0.0.0-20210818161939-5560c4c073ff // indirect
19
19
github.com/kevinburke/ssh_config v1.1.0 // indirect
20
20
github.com/manifoldco/promptui v0.9.0
21
21
github.com/mattn/go-runewidth v0.0.13 // indirect
@@ -27,6 +27,7 @@ require (
27
27
github.com/spf13/viper v1.10.1
28
28
github.com/stretchr/testify v1.7.0
29
29
github.com/xanzy/ssh-agent v0.3.1 // indirect
30
+ go.bug.st/cleanup v1.0.0
30
31
go.bug.st/serial v1.3.3
31
32
go.bug.st/serial.v1 v0.0.0-20191202182710-24a6610f0541 // indirect
32
33
golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3
You can’t perform that action at this time.
0 commit comments