feat: migrate to golang

This commit is contained in:
2026-07-19 20:01:38 +08:00
parent 302d4e6bb5
commit a2630df9e0
69 changed files with 4750 additions and 3369 deletions

57
internal/service/shlex.go Normal file
View File

@ -0,0 +1,57 @@
package service
import (
"fmt"
"strings"
"unicode"
)
// shlexSplit splits s into shell-like words, honoring single and double
// quotes. Small hand-rolled equivalent of Python's shlex.split (used by
// macos_service_wrapper.py / service_manager.py to parse the free-form
// service Args string), avoiding an extra third-party dependency.
func shlexSplit(s string) ([]string, error) {
var words []string
var current strings.Builder
inWord := false
runes := []rune(s)
i := 0
for i < len(runes) {
r := runes[i]
switch {
case r == '\'' || r == '"':
quote := r
i++
closed := false
for i < len(runes) {
if runes[i] == quote {
closed = true
i++
break
}
current.WriteRune(runes[i])
i++
}
if !closed {
return nil, fmt.Errorf("no closing quotation")
}
inWord = true
case unicode.IsSpace(r):
if inWord {
words = append(words, current.String())
current.Reset()
inWord = false
}
i++
default:
current.WriteRune(r)
inWord = true
i++
}
}
if inWord {
words = append(words, current.String())
}
return words, nil
}