-
Notifications
You must be signed in to change notification settings - Fork 24
/
main.go
51 lines (44 loc) · 781 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"context"
"log"
"os"
"os/exec"
"os/signal"
"path/filepath"
"github.com/markbates/grift/cli"
)
func main() {
defer func() {
c := exec.Command("go", "mod", "tidy")
c.Run()
}()
pwd, _ := os.Getwd()
dir := filepath.Join(pwd, ".grifter")
defer os.RemoveAll(dir)
defer func() {
if err := recover(); err != nil {
os.RemoveAll(dir)
log.Fatal(err)
}
}()
ctx := context.Background()
// trap Ctrl+C and call cancel on the context
ctx, cancel := context.WithCancel(ctx)
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
defer func() {
signal.Stop(c)
cancel()
}()
go func() {
select {
case <-c:
cancel()
case <-ctx.Done():
}
}()
if err := cli.Main(ctx, os.Args[1:]); err != nil {
log.Fatal(err)
}
}