@@ -229,9 +229,23 @@ func AddDefaultGroupToConfig(config Config) Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func SanitizeCommand(cmdStr string) ([]string, error) {
|
func SanitizeCommand(cmdStr string) ([]string, error) {
|
||||||
// Remove trailing backslashes
|
var cleanedLines []string
|
||||||
cmdStr = strings.ReplaceAll(cmdStr, "\\ \n", " ")
|
for _, line := range strings.Split(cmdStr, "\n") {
|
||||||
cmdStr = strings.ReplaceAll(cmdStr, "\\\n", " ")
|
trimmed := strings.TrimSpace(line)
|
||||||
|
// Skip comment lines
|
||||||
|
if strings.HasPrefix(trimmed, "#") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// Handle trailing backslashes by replacing with space
|
||||||
|
if strings.HasSuffix(trimmed, "\\") {
|
||||||
|
cleanedLines = append(cleanedLines, strings.TrimSuffix(trimmed, "\\")+" ")
|
||||||
|
} else {
|
||||||
|
cleanedLines = append(cleanedLines, line)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// put it back together
|
||||||
|
cmdStr = strings.Join(cleanedLines, "\n")
|
||||||
|
|
||||||
// Split the command into arguments
|
// Split the command into arguments
|
||||||
var args []string
|
var args []string
|
||||||
|
|||||||
@@ -14,8 +14,14 @@ func TestConfig_SanitizeCommand(t *testing.T) {
|
|||||||
-a "double quotes" \
|
-a "double quotes" \
|
||||||
--arg2 'single quotes'
|
--arg2 'single quotes'
|
||||||
-s
|
-s
|
||||||
|
# comment 1
|
||||||
--arg3 123 \
|
--arg3 123 \
|
||||||
|
|
||||||
|
# comment 2
|
||||||
--arg4 '"string in string"'
|
--arg4 '"string in string"'
|
||||||
|
|
||||||
|
|
||||||
|
# this will get stripped out as well as the white space above
|
||||||
-c "'single quoted'"
|
-c "'single quoted'"
|
||||||
`)
|
`)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|||||||
@@ -11,10 +11,17 @@ import (
|
|||||||
func TestConfig_SanitizeCommand(t *testing.T) {
|
func TestConfig_SanitizeCommand(t *testing.T) {
|
||||||
// does not support single quoted strings like in config_posix_test.go
|
// does not support single quoted strings like in config_posix_test.go
|
||||||
args, err := SanitizeCommand(`python model1.py \
|
args, err := SanitizeCommand(`python model1.py \
|
||||||
-a "double quotes" \
|
|
||||||
|
-a "double quotes" \
|
||||||
-s
|
-s
|
||||||
--arg3 123 \
|
--arg3 123 \
|
||||||
|
|
||||||
|
# comment 2
|
||||||
--arg4 '"string in string"'
|
--arg4 '"string in string"'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# this will get stripped out as well as the white space above
|
||||||
-c "'single quoted'"
|
-c "'single quoted'"
|
||||||
`)
|
`)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|||||||
Reference in New Issue
Block a user