-
Notifications
You must be signed in to change notification settings - Fork 11
/
main.go
66 lines (55 loc) · 1.42 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
package main
import (
"flag"
"fmt"
"github.com/wesovilabs/beyond/internal"
"github.com/wesovilabs/beyond/logger"
"os"
"os/exec"
)
func usage() {
fmt.Println("usage: [env_vars] beyond [beyond_flags] go_command [go_flags]")
fmt.Println("[beyond_flags]")
flag.PrintDefaults()
fmt.Println("\n[go_command]")
fmt.Println(" build: Build compiles the packages named by the import paths")
fmt.Println(" run: Run compiles and runs the named main Go package.")
fmt.Println(" generate: Generate runs commands described by directives within existing files.")
}
func showBanner() {
fmt.Println(internal.Banner)
}
func goCommand(settings *internal.Settings, goArgs []string) *exec.Cmd {
executor := internal.GoCommand(settings, goArgs)
if executor == nil {
return nil
}
return executor.Do()
}
func main() {
settings := internal.BeyondSettingFromCommandLine(os.Args[1:])
goArgs := internal.RemoveBeyondArguments(os.Args[1:])
goCmd := goCommand(settings, goArgs)
if goCmd == nil {
showBanner()
usage()
return
}
if settings.Verbose {
logger.Enable()
defer logger.Close()
showBanner()
}
if !settings.Work {
defer func() {
logger.Infof("wipe out directory %s", settings.Output)
if err := os.RemoveAll(settings.Output); err != nil {
logger.Error(err.Error())
}
}()
} else {
fmt.Printf("[ WORKDIR ] %s\n", settings.Output)
}
exitStatus := internal.ExecuteMain(goCmd, settings)
os.Exit(exitStatus)
}