@@ -7,7 +7,6 @@ parse_launch_processes() {
7
7
local launch_toml_file=" ${2} "
8
8
9
9
local type=" "
10
- local command=" "
11
10
local line
12
11
13
12
while IFS= read -r line; do
@@ -16,12 +15,39 @@ parse_launch_processes() {
16
15
type=" ${BASH_REMATCH[1]} "
17
16
fi
18
17
19
- # Extract the command from lines like `command = ["bash", "-c", "run_command"]`
20
- if [[ ${line} =~ ^command[[:space:]]* = [[:space:]]* \[\" bash\" ,[[:space:]]* \" -c\" ,[[:space:]]* \" (.* )\" [[:space:]]* \] ]]; then
21
- command=" ${BASH_REMATCH[1]} "
22
- _processes[" ${type} " ]=" ${command} "
18
+ # Extract command array from lines like `command = ["bash", "-c", "run_command"]`,
19
+ # `command = ["dotnet", "test", "foo.csproj"]`.
20
+ # `command = ["dotnet", "test", "foo bar.csproj", "--verbosity", "normal"]`.
21
+ if [[ ${line} =~ ^command[[:space:]]* = [[:space:]]* \[ (.* )\] ]]; then
22
+ local command=()
23
+ local raw_command=" ${BASH_REMATCH[1]} "
24
+ local quoted_command=()
25
+
26
+ # Extract quoted values
27
+ while [[ ${raw_command} =~ \" ([^\" ]+)\" ]]; do
28
+ local arg=" ${BASH_REMATCH[1]} "
29
+ command+=(" ${arg} " )
30
+
31
+ # Quote arg if it differs from it's own `printf '%q'` formatting. This
32
+ # is a hack to check for special characters that'd need escaping (while
33
+ # preferring to quote the arg for readability) without using regex, sed etc.
34
+ if [[ " $( printf ' %q' " ${arg} " ) " != " ${arg} " ]]; then
35
+ quoted_command+=(" \" ${arg} \" " )
36
+ else
37
+ quoted_command+=(" ${arg} " )
38
+ fi
39
+
40
+ raw_command=${raw_command#* \" " ${arg} " \" }
41
+ done
42
+
43
+ # Store the command, handling `bash -c` case where we only want the (unquoted) third argument
44
+ if [[ ${# command[@]} -ge 3 && " ${command[0]} " == " bash" && " ${command[1]} " == " -c" ]]; then
45
+ _processes[" ${type} " ]=" ${command[2]} "
46
+ else
47
+ _processes[" ${type} " ]=" ${quoted_command[*]} "
48
+ fi
49
+
23
50
type=" "
24
- command=" "
25
51
fi
26
52
done < " ${launch_toml_file} "
27
53
}
0 commit comments