improve cmd parsing (#22)

Switch from using a naive strings.Fields() to shlex.Split() for parsing the model startup command into a string[]. This makes parsing much more reliable around newlines, quotes, etc.
This commit is contained in:
Benson Wong
2024-12-01 09:02:58 -08:00
committed by GitHub
parent cf82b3c633
commit 9fc5d5b5eb
4 changed files with 25 additions and 9 deletions

View File

@@ -5,6 +5,7 @@ import (
"os"
"strings"
"github.com/google/shlex"
"gopkg.in/yaml.v3"
)
@@ -81,7 +82,10 @@ func SanitizeCommand(cmdStr string) ([]string, error) {
cmdStr = strings.ReplaceAll(cmdStr, "\\\n", " ")
// Split the command into arguments
args := strings.Fields(cmdStr)
args, err := shlex.Split(cmdStr)
if err != nil {
return nil, err
}
// Ensure the command is not empty
if len(args) == 0 {