-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
68 lines (58 loc) · 2.47 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
package main
import (
"fmt"
"net"
"os"
"os/signal"
"github.com/go-sharp/go-runner/log"
"github.com/go-sharp/go-runner/runner"
flag "github.com/spf13/pflag"
)
// Version is the current application version
const Version = "0.3.0"
func main() {
var dlvPort = new(uint16)
cd := flag.StringP("entry", "e", "./", "The directory with the main.go file")
testdirs := flag.StringSliceP("tests", "t", []string{"./"}, "Test directories in which the go test command will be executed")
skipTests := flag.BoolP("skip-tests", "s", false, "Don't run any tests")
recursiveTests := flag.BoolP("test-non-recursive", "r", false, "Don't run tests recursively")
watchDirs := flag.StringSliceP("watch-dirs", "w", []string{"./"}, "Directories to listen recursively for file changes (*.go, go.mod, go.sum)")
excludeDirs := flag.StringSliceP("exclude-dirs", "x", []string{}, "Don't listen to changes in these directories")
useDlv := flag.BoolP("use-dlv", "d", false, "Use delve to run the program")
flag.Uint16VarP(dlvPort, "port", "p", 2345, "Listen port for delve")
dlvIP := flag.IPP("address", "a", net.ParseIP("0.0.0.0"), "Listen address for delve")
dlvAPIV := flag.IntP("api-version", "v", 2, "API version to use for delve server")
help := flag.BoolP("help", "h", false, "Show help")
ldFlags := flag.StringP("ldflags", "l", "", "Linker flags to pass to the go build tool")
gcFlags := flag.StringP("gcflags", "g", "", "Compiler flags to pass to the go build tool")
useRace := flag.BoolP("race", "c", false, "Enable race detector")
tags := flag.StringSliceP("tags", "", []string{}, "Tags to pass to the go build tool")
flag.Parse()
if *help {
fmt.Printf("Usage for %v | Version %v:\n\n", os.Args[0], Version)
fmt.Printf("%v [Options] [-- arguments (ex. -c config.json --http=:8080 1234)] \n\nOptions:\n", os.Args[0])
flag.PrintDefaults()
os.Exit(0)
}
r := runner.NewRunner(runner.WorkingDirectory(*cd),
runner.TestWorkingDirectories(*testdirs...),
runner.RunTests(!*skipTests),
runner.RecursiveTests(!*recursiveTests),
runner.WatchDirs(*watchDirs...),
runner.ExcludeDirs(*excludeDirs...),
runner.CommandArgs(flag.Args()...),
runner.UseDelve(*useDlv, *dlvAPIV, *dlvPort, *dlvIP),
runner.UseRaceDetector(*useRace),
runner.UseLDFlags(*ldFlags),
runner.UseGCFlags(*gcFlags),
runner.UseTags(*tags...))
if err := r.Watch(); err != nil {
log.Errorln(err)
os.Exit(1)
}
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
<-c
log.Infoln("Shutting down go-runner...")
r.Stop()
}