File tree 1 file changed +10
-5
lines changed
1 file changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -3,14 +3,16 @@ package cli
3
3
import (
4
4
"context"
5
5
"fmt"
6
+ "os"
7
+ "os/signal"
8
+ "syscall"
6
9
"time"
7
10
8
11
"git.numtide.com/numtide/treefmt/internal/cache"
9
12
"git.numtide.com/numtide/treefmt/internal/format"
10
13
11
14
"github.com/charmbracelet/log"
12
15
"github.com/juju/errors"
13
- "github.com/ztrue/shutdown"
14
16
"golang.org/x/sync/errgroup"
15
17
)
16
18
@@ -33,9 +35,6 @@ func (f *Format) Run() error {
33
35
ctx , cancel := context .WithCancel (context .Background ())
34
36
defer cancel ()
35
37
36
- // register shutdown hook
37
- shutdown .Add (cancel )
38
-
39
38
// read config
40
39
cfg , err := format .ReadConfigFile (Cli .ConfigFile )
41
40
if err != nil {
@@ -186,7 +185,13 @@ func (f *Format) Run() error {
186
185
return cache .ChangeSet (ctx , Cli .TreeRoot , pathsCh )
187
186
})
188
187
189
- // shutdown.Listen(syscall.SIGINT, syscall.SIGTERM)
188
+ // listen for shutdown and call cancel if required
189
+ go func () {
190
+ exit := make (chan os.Signal , 1 )
191
+ signal .Notify (exit , os .Interrupt , syscall .SIGTERM )
192
+ <- exit
193
+ cancel ()
194
+ }()
190
195
191
196
return eg .Wait ()
192
197
}
You can’t perform that action at this time.
0 commit comments