-
-
Notifications
You must be signed in to change notification settings - Fork 97
/
main.go
72 lines (59 loc) · 1.58 KB
/
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"log"
"os"
"os/signal"
"syscall"
"github.com/steebchen/prisma-client-go/cli"
"github.com/steebchen/prisma-client-go/logger"
)
func main() {
if len(os.Args) > 1 {
args := os.Args[1:]
logger.Debug.Printf("invoking command %+v", args)
switch args[0] {
case "prefetch":
// just run prisma -v to trigger the download
if err := cli.Run([]string{"-v"}, true); err != nil {
panic(err)
}
os.Exit(0)
return
case "init":
// override default init flags
args = append(args, "--generator-provider", "go run github.com/steebchen/prisma-client-go")
if err := cli.Run(args, true); err != nil {
panic(err)
}
os.Exit(0)
return
}
// prisma CLI
if err := cli.Run(args, true); err != nil {
panic(err)
}
return
}
// running the prisma generator
logger.Debug.Printf("invoking prisma")
// if this wasn't actually invoked by the prisma generator, print a warning and exit
if os.Getenv("PRISMA_GENERATOR_INVOCATION") == "" {
logger.Info.Printf("This command is only meant to be invoked internally. Please run the following instead:")
logger.Info.Printf("`go run github.com/steebchen/prisma-client-go <command>`")
logger.Info.Printf("e.g.")
logger.Info.Printf("`go run github.com/steebchen/prisma-client-go generate`")
os.Exit(1)
}
// exit when signal triggers
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
go func() {
<-c
os.Exit(1)
}()
if err := invokePrisma(); err != nil {
log.Printf("error occurred when invoking prisma: %s", err)
os.Exit(1)
}
logger.Debug.Printf("success")
}