mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-04-15 11:56:37 +02:00
Allow passing multiple flags to the cli runner
This is useful for example to pass both -slow and -debug. Since we're about to add yet another flag in the next commit, it becomes even more important. Plus, it makes the code a little nicer too.
This commit is contained in:
parent
26d180a50a
commit
8081b59a02
@ -26,6 +26,29 @@ Usage:
|
|||||||
> go run cmd/integration_test/main.go 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
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if len(os.Args) < 2 {
|
if len(os.Args) < 2 {
|
||||||
log.Fatal(usage)
|
log.Fatal(usage)
|
||||||
@ -35,24 +58,14 @@ func main() {
|
|||||||
case "help":
|
case "help":
|
||||||
fmt.Println(usage)
|
fmt.Println(usage)
|
||||||
case "cli":
|
case "cli":
|
||||||
testNames := os.Args[2:]
|
|
||||||
slow := false
|
slow := false
|
||||||
sandbox := false
|
sandbox := false
|
||||||
waitForDebugger := false
|
waitForDebugger := false
|
||||||
// get the next arg if it's --slow
|
testNames := parseFlags(os.Args[2:], []flagInfo{
|
||||||
if len(os.Args) > 2 {
|
{"slow", &slow},
|
||||||
if os.Args[2] == "--slow" || os.Args[2] == "-slow" {
|
{"sandbox", &sandbox},
|
||||||
testNames = os.Args[3:]
|
{"debug", &waitForDebugger},
|
||||||
slow = true
|
})
|
||||||
} else if os.Args[2] == "--sandbox" || os.Args[2] == "-sandbox" {
|
|
||||||
testNames = os.Args[3:]
|
|
||||||
sandbox = true
|
|
||||||
} else if os.Args[2] == "--debug" || os.Args[2] == "-debug" {
|
|
||||||
testNames = os.Args[3:]
|
|
||||||
waitForDebugger = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
clients.RunCLI(testNames, slow, sandbox, waitForDebugger)
|
clients.RunCLI(testNames, slow, sandbox, waitForDebugger)
|
||||||
case "tui":
|
case "tui":
|
||||||
clients.RunTUI()
|
clients.RunTUI()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user