fix(splitargs): wrong code, check should be outside of loop

feat(config): added WMPidProxyCheckVersion and WMExecCheckVersion to the interface; mutex for accessing viper
fixed(docker/bookworm-newconfig): golang version and config path
feat(UtilDepCheck): added utility dependency check before running the task
This commit is contained in:
2024-03-27 23:04:30 +11:00
parent a63646aab2
commit 7db6f6f8f3
13 changed files with 295 additions and 40 deletions

View File

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

View File

@@ -0,0 +1,7 @@
package cli
import "testing"
func TestSplitArgs(t *testing.T) {
SplitArgs([]string{"wmexec", "--user", "1200", "--", "wmspawner"})
}