Skip to content

Commit 1b472d2

Browse files
committed
made script command parsing a bit more general + updated readme
1 parent d1ebe82 commit 1b472d2

2 files changed

Lines changed: 8 additions & 4 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 can run scripts that outputs arguments to be used. This can be done by wrapping the argument with \${}, then specifying the language to run the script with as well as the path to the script, e.g. `--project=${bash path/to/script.sh}`. The extension expects the script to output the value to set the argument to wrapped with \${}, so with the argument `--project=${bash path/to/script.sh}` the script will be run and expected to create a compile_commands.json file whose path will be output as such: `${path/to/compile_commands.json}`.
13+
- **Dynamic config**: The extension supports runing scripts to generate arguments to pass to cppcheck. This can be done by setting the argument to command to run wrapped with \${}, e.g. `--project=${bash path/to/script.sh}`. The script is expected to output the argument wrapped with \${}, so with the argument `--project=${bash path/to/script.sh}` the script will be run and expected to create a compile_commands.json file whose path will be printed out as such: `${path/to/compile_commands.json}`.
1414
## Requirements
1515

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

src/util/scripts.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import { execFile } from "child_process";
22
import { resolvePath } from './path';
33

4-
function runScript(scriptPath: string): Promise<string> {
4+
function runScript(scriptCommand: string): Promise<string> {
5+
const scriptParts : string[] = scriptCommand.split(" ");
6+
// ASSUMPTION: script path will be the last part of the command
7+
const scriptPath = scriptParts[scriptParts.length -1];
58
const absoluteScriptPath = resolvePath(scriptPath);
6-
const workspaceFolder = resolvePath('${workspaceFolder}');
9+
const joinedCommand = scriptParts.slice(0, scriptParts.length -1).join(" ") + " " + absoluteScriptPath;
10+
console.log('joined command', joinedCommand);
711
return new Promise((resolve, reject) => {
8-
execFile(absoluteScriptPath, [], { cwd: workspaceFolder }, (error, stdout, stderr) => {
12+
execFile(joinedCommand, [], { cwd: resolvePath('${workspaceFolder}') }, (error, stdout, stderr) => {
913
if (error) {
1014
reject(error);
1115
return;

0 commit comments

Comments
 (0)