-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
58 lines (50 loc) · 2.02 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
package main
import (
"flag"
"fmt"
"os"
"runtime/debug"
"github.com/jxskiss/mcli"
"github.com/multisig-labs/gogocode-tester-sample/pkg/testcase_sample"
"github.com/multisig-labs/gogocode-tester-sample/pkg/version"
)
func main() {
defer handlePanic()
mcli.Add("sample", testSampleCmd, "Run the tester for course Sample against a binary. Returns slug of last successful test case")
mcli.Add("version", versionCmd, "Display version")
mcli.Run()
}
func testSampleCmd() {
args := struct {
Executable string `cli:"--exe, Executable to test" default:"./run.sh"`
}{}
mcli.Parse(&args, mcli.WithErrorHandling(flag.ExitOnError))
// Ignore error (its already been logged) and return last successful stage slug
slug, _ := testcase_sample.RunTestCases(args.Executable)
fmt.Print(slug)
}
func versionCmd() {
fmt.Println("Build Date:", version.BuildDate)
fmt.Println("Git Commit:", version.GitCommit)
fmt.Println("Version:", version.Version)
fmt.Println("Go Version:", version.GoVersion)
fmt.Println("OS / Arch:", version.OsArch)
}
func handlePanic() {
if panicPayload := recover(); panicPayload != nil {
stack := string(debug.Stack())
fmt.Fprintln(os.Stderr, "================================================================================")
fmt.Fprintln(os.Stderr, " Fatal error. Sorry! You found a bug.")
fmt.Fprintln(os.Stderr, " Please copy all of this info into an issue at")
fmt.Fprintln(os.Stderr, " https://github.com/multisig-labs")
fmt.Fprintln(os.Stderr, "================================================================================")
fmt.Fprintf(os.Stderr, "Version: %s\n", version.Version)
fmt.Fprintf(os.Stderr, "Build Date: %s\n", version.BuildDate)
fmt.Fprintf(os.Stderr, "Git Commit: %s\n", version.GitCommit)
fmt.Fprintf(os.Stderr, "Go Version: %s\n", version.GoVersion)
fmt.Fprintf(os.Stderr, "OS / Arch: %s\n", version.OsArch)
fmt.Fprintf(os.Stderr, "Panic: %s\n\n", panicPayload)
fmt.Fprintln(os.Stderr, stack)
os.Exit(1)
}
}