MCPcopy Create free account
hub / github.com/ZToolsCenter/ZTools / parseCommandString

Function parseCommandString

src/main/core/commandLauncher/linuxLauncher.ts:11–38  ·  view source on GitHub ↗

* 将可能包含参数的命令字符串拆分为 [可执行文件, ...参数列表] * 例如: "/usr/bin/ghostty --gtk-single-instance=true" → ["/usr/bin/ghostty", "--gtk-single-instance=true"]

(cmd: string)

Source from the content-addressed store, hash-verified

9 * 例如: "/usr/bin/ghostty --gtk-single-instance=true" → ["/usr/bin/ghostty", "--gtk-single-instance=true"]
10 */
11function parseCommandString(cmd: string): [string, string[]] {
12 const parts: string[] = []
13 let current = ''
14 let inQuote: string | null = null
15
16 for (let i = 0; i < cmd.length; i++) {
17 const ch = cmd[i]
18 if (inQuote) {
19 if (ch === inQuote) {
20 inQuote = null
21 } else {
22 current += ch
23 }
24 } else if (ch === '"' || ch === "'") {
25 inQuote = ch
26 } else if (/\s/.test(ch)) {
27 if (current) {
28 parts.push(current)
29 current = ''
30 }
31 } else {
32 current += ch
33 }
34 }
35 if (current) parts.push(current)
36
37 return [parts[0], parts.slice(1)]
38}
39
40export async function launchApp(
41 appPath: string,

Callers 1

launchAppFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected