Files
wingmate/cmd/cli/splitargs.go
T
suyono f2bfd6e60b fix(init): removed unnecessary error message when waiting for child process; race with wait all
fix(exec): fallback to os.Args when no delimiter found
fix(pidproxy): fallback to os.Args when no delimiter found
fix(splitargs): return full selfArgs
fix(experiment/starter): replaced bool no-wait with count
test(docker/bookworm-newconfig): added test for background process + pid proxy
2024-03-28 22:21:57 +11:00

38 lines
598 B
Go

package cli
import (
"errors"
)
func SplitArgs(args []string) ([]string, []string, error) {
var (
i int
arg string
selfArgs []string
childArgs []string
)
found := false
for i, arg = range args {
if arg == "--" {
found = true
if i+1 == len(args) {
return nil, nil, errors.New("invalid argument")
}
if len(args[i+1:]) == 0 {
return nil, nil, errors.New("invalid argument")
}
selfArgs = args[:i]
childArgs = args[i+1:]
break
}
}
if !found {
return nil, nil, errors.New("invalid argument")
}
return selfArgs, childArgs, nil
}