MCPcopy Create free account
hub / github.com/52funny/pikpakcli / parseShellArgs

Function parseShellArgs

internal/shell/shell.go:1140–1191  ·  view source on GitHub ↗

parseShellArgs parses shell-like arguments

(input string)

Source from the content-addressed store, hash-verified

1138
1139// parseShellArgs parses shell-like arguments
1140func parseShellArgs(input string) []string {
1141 var args []string
1142 var current strings.Builder
1143 inDoubleQuote := false
1144 inSingleQuote := false
1145 escaped := false
1146
1147 for i := 0; i < len(input); i++ {
1148 ch := input[i]
1149
1150 if escaped {
1151 current.WriteByte(ch)
1152 escaped = false
1153 continue
1154 }
1155
1156 switch ch {
1157 case '\\':
1158 if inSingleQuote {
1159 current.WriteByte(ch)
1160 } else {
1161 escaped = true
1162 }
1163 case '"':
1164 if inSingleQuote {
1165 current.WriteByte(ch)
1166 } else {
1167 inDoubleQuote = !inDoubleQuote
1168 }
1169 case '\'':
1170 if inDoubleQuote {
1171 current.WriteByte(ch)
1172 } else {
1173 inSingleQuote = !inSingleQuote
1174 }
1175 case ' ', '\t':
1176 if inDoubleQuote || inSingleQuote {
1177 current.WriteByte(ch)
1178 } else if current.Len() > 0 {
1179 args = append(args, current.String())
1180 current.Reset()
1181 }
1182 default:
1183 current.WriteByte(ch)
1184 }
1185 }
1186
1187 if current.Len() > 0 {
1188 args = append(args, current.String())
1189 }
1190 return args
1191}
1192
1193func escapeShellCompletion(value string) string {
1194 var escaped strings.Builder

Callers 2

StartFunction · 0.85
TestParseShellArgsFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestParseShellArgsFunction · 0.68