forked from air-verse/air
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
88 lines (74 loc) · 1.59 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package main
import (
"flag"
"fmt"
"log"
"os"
"os/signal"
"syscall"
"github.com/Robfz/air/runner"
)
var (
cfgPath string
debugMode bool
showVersion bool
cmdArgs map[string]runner.TomlInfo
runArgs []string
)
func helpMessage() {
fmt.Fprintf(flag.CommandLine.Output(), "Usage of %s:\n\n", os.Args[0])
fmt.Printf("If no command is provided %s will start the runner with the provided flags\n\n", os.Args[0])
fmt.Println("Commands:")
fmt.Print(" init creates a .air.toml file with default settings to the current directory\n\n")
fmt.Println("Flags:")
flag.PrintDefaults()
}
func init() {
parseFlag(os.Args[1:])
}
func parseFlag(args []string) {
flag.Usage = helpMessage
flag.StringVar(&cfgPath, "c", "", "config path")
flag.BoolVar(&debugMode, "d", false, "debug mode")
flag.BoolVar(&showVersion, "v", false, "show version")
cmd := flag.CommandLine
cmdArgs = runner.ParseConfigFlag(cmd)
flag.CommandLine.Parse(args)
}
func main() {
fmt.Printf(`
__ _ ___
/ /\ | | | |_)
/_/--\ |_| |_| \_ %s, built with Go %s
`, airVersion, goVersion)
if showVersion {
return
}
if debugMode {
fmt.Println("[debug] mode")
}
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
var err error
cfg, err := runner.InitConfig(cfgPath)
if err != nil {
log.Fatal(err)
return
}
cfg.WithArgs(cmdArgs)
r, err := runner.NewEngineWithConfig(cfg, debugMode)
if err != nil {
log.Fatal(err)
return
}
go func() {
<-sigs
r.Stop()
}()
defer func() {
if e := recover(); e != nil {
log.Fatalf("PANIC: %+v", e)
}
}()
r.Run()
}