Skip to content

Commit e9127dd

Browse files
Support stdin resolve vars
1 parent db23a61 commit e9127dd

File tree

7 files changed

+24
-5
lines changed

7 files changed

+24
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Change Log
22

3+
## [1.18.0] 2025-05-13
4+
5+
- Support stdinResolveVars (#145)
6+
37
## [1.18.0] 2025-05-06
48

59
- Support stdin (#145)

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ VSCode renders it like this:
9797
* `command`: the system command to be executed (must be in PATH). If given as an array, the elements are joined by spaces.
9898
* `commandArgs`: if provided, `command` is interpreted as the binary to run and `commandArgs` are the arguments. This is useful if the binary you want to run has spaces (like `C:\Program Files\*`). This translates to `child_process.execFileSync(command, commandArgs)`.
9999
* `stdin`: if provided, this string is sent to the standard input of the command
100+
* `stdinResolveVars`: whether to perform variable substitution (see below) for `stdin` (default true).
100101
* `cwd`: the directory from within it will be executed
101102
* `env`: key-value pairs to use as environment variables (it won't append the variables to the current existing ones. It will replace instead)
102103
* `useFirstResult`: skip 'Quick Pick' dialog and use first result returned from the command

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"displayName": "Tasks Shell Input",
44
"description": "Use shell commands as input for your tasks",
55
"icon": "icon.png",
6-
"version": "1.18.0",
6+
"version": "1.18.1",
77
"publisher": "augustocdias",
88
"repository": {
99
"url": "https://github.com/augustocdias/vscode-shell-command"

src/lib/CommandHandler.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ describe("Argument parsing", () => {
453453
multiselectSeparator: " ",
454454
stdio: "stdout",
455455
extraTestThing: 42,
456+
stdinResolveVars: true,
456457
});
457458
});
458459

src/lib/CommandHandler.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,14 @@ export class CommandHandler {
6868
allowCustomValues: parseBoolean(args.allowCustomValues, false),
6969
warnOnStderr: parseBoolean(args.warnOnStderr, true),
7070
multiselect: parseBoolean(args.multiselect, false),
71+
stdinResolveVars: parseBoolean(args.multiselect, true),
7172
multiselectSeparator: args.multiselectSeparator ?? " ",
7273
stdio: ["stdout", "stderr", "both"].includes(args.stdio as string) ? args.stdio : "stdout",
7374
...args,
7475
} as ShellCommandOptions;
7576
}
7677

77-
protected async resolveArgs() {
78+
protected async resolveVariables() {
7879
const resolver = new VariableResolver(
7980
this.input,
8081
this.userInputContext,
@@ -90,6 +91,17 @@ export class CommandHandler {
9091
this.command = command;
9192
}
9293

94+
if (this.stdin !== undefined && this.args.stdinResolveVars === true) {
95+
const resolvedStdin = await resolver.resolve(this.stdin)
96+
if (resolvedStdin === undefined) {
97+
throw new ShellCommandException(
98+
"Your stdin is badly formatted and variables could not be resolved. Set stdinResolveVars=false to prevent stdin vars resolving",
99+
);
100+
} else {
101+
this.stdin = resolvedStdin;
102+
}
103+
}
104+
93105
if (this.commandArgs !== undefined) {
94106
for (const i in this.commandArgs) {
95107
const item = await resolver.resolve(this.commandArgs[i]);
@@ -125,7 +137,7 @@ export class CommandHandler {
125137
// Get the result, either by showing a dropdown or taking the first / only
126138
// option
127139
async getResult() {
128-
await this.resolveArgs();
140+
await this.resolveVariables();
129141

130142
const result = await this.runCommand();
131143
const nonEmptyInput = this.parseResult(result);

src/lib/ShellCommandOptions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export interface ShellCommandOptions
44
command: unknown;
55
commandArgs?: unknown;
66
stdin?: string;
7+
stdinResolveVars?: boolean;
78
env?: { [s: string]: string };
89
useFirstResult?: boolean;
910
useSingleResult?: boolean;

0 commit comments

Comments
 (0)