1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-02-03 13:21:56 +02:00

85 lines
1.9 KiB
Go
Raw Normal View History

2022-08-14 14:33:44 +10:00
package main
import (
"fmt"
"log"
"os"
"github.com/jesseduffield/lazygit/pkg/integration/clients"
)
var usage = `
Usage:
See https://github.com/jesseduffield/lazygit/tree/master/pkg/integration/README.md
CLI mode:
2022-08-22 20:43:19 +10:00
> go run cmd/integration_test/main.go cli [--slow] [--sandbox] <test1> <test2> ...
2022-08-14 14:33:44 +10:00
If you pass no test names, it runs all tests
Accepted environment variables:
INPUT_DELAY (e.g. 200): the number of milliseconds to wait between keypresses or mouse clicks
2022-08-14 14:33:44 +10:00
TUI mode:
> go run cmd/integration_test/main.go tui
This will open up a terminal UI where you can run tests
Help:
> go run cmd/integration_test/main.go help
`
type flagInfo struct {
name string // name of the flag; can be used with "-" or "--"
flag *bool // a pointer to the variable that should be set to true when this flag is passed
}
// Takes the args that you want to parse (excluding the program name and any
// subcommands), and returns the remaining args with the flags removed
func parseFlags(args []string, flags []flagInfo) []string {
outer:
for len(args) > 0 {
for _, f := range flags {
if args[0] == "-"+f.name || args[0] == "--"+f.name {
*f.flag = true
args = args[1:]
continue outer
}
}
break
}
return args
}
2022-08-14 14:33:44 +10:00
func main() {
if len(os.Args) < 2 {
log.Fatal(usage)
}
switch os.Args[1] {
case "help":
fmt.Println(usage)
case "cli":
2022-08-14 20:47:09 +10:00
slow := false
2022-08-22 20:43:19 +10:00
sandbox := false
waitForDebugger := false
raceDetector := false
testNames := parseFlags(os.Args[2:], []flagInfo{
{"slow", &slow},
{"sandbox", &sandbox},
{"debug", &waitForDebugger},
{"race", &raceDetector},
})
clients.RunCLI(testNames, slow, sandbox, waitForDebugger, raceDetector)
2022-08-14 14:33:44 +10:00
case "tui":
raceDetector := false
remainingArgs := parseFlags(os.Args[2:], []flagInfo{
{"race", &raceDetector},
})
if len(remainingArgs) > 0 {
log.Fatal("tui only supports the -race argument.")
}
clients.RunTUI(raceDetector)
2022-08-14 14:33:44 +10:00
default:
log.Fatal(usage)
}
}