Skip to content

Commit 1905641

Browse files
committed
fix pyOCD debug config
1 parent eb258d6 commit 1905641

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

src/extension.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2114,7 +2114,8 @@ class ExternalDebugConfigProvider implements vscode.DebugConfigurationProvider {
21142114
}
21152115
}
21162116
if (flasherCfg.otherCmds)
2117-
cliArgs.push(flasherCfg.otherCmds);
2117+
utility.parseCliArgs(flasherCfg.otherCmds)
2118+
.forEach(s => cliArgs.push(s))
21182119
if (flasherCfg.speed) {
21192120
cliArgs.push('-f');
21202121
cliArgs.push(flasherCfg.speed);

src/utility.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,45 @@ export const TIME_ONE_MINUTE = 60 * 1000;
4949
export const TIME_ONE_HOUR = 3600 * 1000;
5050
export const TIME_ONE_DAY = 24 * 3600 * 1000;
5151

52+
export function parseCliArgs(cliStr: string): string[] {
53+
54+
let argsLi: string[] = [];
55+
let inQuote = false;
56+
let curArg = '';
57+
58+
for(let char_ of cliStr) {
59+
// is a "..." start or end
60+
if (char_ === '"' && (curArg.length === 0 || curArg[curArg.length - 1] !== '\\')) {
61+
if (inQuote) {
62+
inQuote = false;
63+
if (curArg && curArg.trim() !== '')
64+
argsLi.push(curArg);
65+
curArg = '';
66+
} else {
67+
inQuote = true;
68+
}
69+
continue; // skip '"'
70+
}
71+
// in "..." region
72+
if (inQuote) {
73+
curArg += char_;
74+
} else { // out "..." region
75+
if (char_ === ' ' || char_ === '\t') {
76+
if (curArg && curArg.trim() !== '')
77+
argsLi.push(curArg);
78+
curArg = '';
79+
} else {
80+
curArg += char_;
81+
}
82+
}
83+
}
84+
85+
if (curArg && curArg.trim() !== '')
86+
argsLi.push(curArg);
87+
88+
return argsLi;
89+
}
90+
5291
export async function probers_install(cwd?: string) {
5392

5493
let commandLine: string;

0 commit comments

Comments
 (0)