Skip to content

Commit 486f457

Browse files
committed
fix/ #53 changed syntax for executing commands through argument setting
1 parent 355f12b commit 486f457

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
- **Diagnostic cleanup**: When you close a file, its diagnostics are automatically cleared.
1111
- **Project file support**: You can feed your project file to cppcheck through the `--project` flag in the `cppcheck-official.arguments` field in the extension settings.
1212
- **Warning notes**: Display notes for warnings when those are available
13-
- **Dynamic config**: The extension supports running a script to generate arguments to pass to cppcheck. This can be done by including the command in the argument field wrapped with \${}, e.g. `--suppress=memleak:src/file1.cpp ${bash path/to/script.sh}`. The script is expected to output the argument(s) wrapped with \${}. If the script e.g. creates a project file it should print out as `${--project=path/to/projectfile.json}`. This output will be spliced into the argument string as such: `--suppress=memleak:src/file1.cpp --project=path/to/projectfile.json`.
13+
- **Dynamic config**: The extension supports running a script to generate arguments to pass to cppcheck. This can be done by including the command in the argument field wrapped with \@(), e.g. `--suppress=memleak:src/file1.cpp \@(bash path/to/script.sh)`. The script is expected to output the argument(s) wrapped with \@(). If the script e.g. creates a project file it should print out as `@(--project=path/to/projectfile.json)`. This output will be spliced into the argument string as such: `--suppress=memleak:src/file1.cpp --project=path/to/projectfile.json`.
1414
## Requirements
1515

1616
**Cppcheck** must be installed on your system.

src/extension.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,15 @@ export async function activate(context: vscode.ExtensionContext) {
9494
var args = config.get<string>("cppcheck-official.arguments", "");
9595
var processedArgs = '';
9696
// If argument field contains command to run script we do so here
97-
if (args.includes('${')) {
98-
const scriptCommand = args.split("${")[1].split("}")[0];
97+
if (args.includes('@(')) {
98+
const scriptCommand = args.split("@(")[1].split(")")[0];
99+
console.log('script command ', scriptCommand);
99100
const scriptOutput = await runCommand(scriptCommand);
100101
// We expect that the script output that is to be used as arguments will be wrapped with ${}
101-
const scriptOutputTrimmed = scriptOutput.split("${")[1].split("}")[0];
102-
processedArgs = args.split("${")[0] + scriptOutputTrimmed + args.split("}")?.[1];
102+
console.log('output', scriptOutput);
103+
const scriptOutputTrimmed = scriptOutput.split("@(")[1].split(")")[0];
104+
console.log('output trimmed', scriptOutputTrimmed);
105+
processedArgs = args.split("@(")[0] + scriptOutputTrimmed + args.split(")")?.[1];
103106
} else {
104107
processedArgs = args;
105108
}

0 commit comments

Comments
 (0)