Skip to content

Commit fd8cec9

Browse files
Merge pull request #156 from augustocdias/allow_empty
Add filterEmptyResults
2 parents 4ea9c4d + b2ac38f commit fd8cec9

7 files changed

Lines changed: 22 additions & 13 deletions

File tree

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.19.0] 2025-07-02
4+
5+
- Allow not filtering empty results (#155)
6+
37
## [1.18.3] 2025-05-28
48

59
- Extracted the `taskId` criteria while searching the input. (#131)

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ VSCode renders it like this:
107107
* `multiselect`: If true, it's possible to select multiple values. They are joined by `multiselectSeparator`. Has no effect with `useFirstResult`.
108108
* `multiselectSeparator`: The string with which to join multiple options when `multiselect` is true (default `" "`). Has no effect without `multiselect`.
109109
* `warnOnStderr`: If true, a warning message is shown if the command outputs anything on stderr (default: true). Has no effect if `stdio` is not `stdout`.
110+
* `filterEmptyResults`: If true, empty lines output on `stdio` are filtered out (default: true).
110111
* `taskId`: Unique id to use for storing the last-used value.
111112
* `rememberAs`: Specify the `taskId` of another input to share history with that input.
112113
* `fieldSeparator`: the string that separates `value`, `label`, `description` and `detail` fields

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.3",
6+
"version": "1.19.0",
77
"publisher": "augustocdias",
88
"repository": {
99
"url": "https://github.com/augustocdias/vscode-shell-command"

src/lib/CommandHandler.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -448,8 +448,8 @@ describe("Errors", async () => {
448448
child_process,
449449
);
450450

451-
expect(() => handler.handle()).rejects.toThrowError(
452-
"The command for input 'inputTest' returned empty result.");
451+
await expect(() => handler.handle()).rejects.toThrowError(
452+
"The command for input 'inputTest' didn't output any results.");
453453
});
454454

455455
test("It should NOT trigger an error with defaultOptions", async () => {
@@ -468,8 +468,8 @@ describe("Errors", async () => {
468468
child_process,
469469
);
470470

471-
expect(() => handler.handle()).rejects.not.toThrowError(
472-
"The command for input 'inputTest' returned empty result.");
471+
await expect(() => handler.handle()).rejects.not.toThrowError(
472+
"The command for input 'inputTest' didn't output any results.");
473473
});
474474
});
475475

@@ -485,6 +485,7 @@ describe("Argument parsing", () => {
485485
useSingleResult: false,
486486
multiselect: false,
487487
warnOnStderr: true,
488+
filterEmptyResults: true,
488489
multiselectSeparator: " ",
489490
stdio: "stdout",
490491
extraTestThing: 42,

src/lib/CommandHandler.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export class CommandHandler {
7070
warnOnStderr: parseBoolean(args.warnOnStderr, true),
7171
multiselect: parseBoolean(args.multiselect, false),
7272
stdinResolveVars: parseBoolean(args.stdinResolveVars, true),
73+
filterEmptyResults: parseBoolean(args.filterEmptyResults, true),
7374
multiselectSeparator: args.multiselectSeparator ?? " ",
7475
stdio: ["stdout", "stderr", "both"].includes(args.stdio as string) ? args.stdio : "stdout",
7576
} as ShellCommandOptions;
@@ -206,8 +207,8 @@ export class CommandHandler {
206207

207208
protected parseResult(commandOutput: { stdout: string, stderr: string }):
208209
QuickPickItem[] {
209-
const stdout = commandOutput.stdout.trim();
210-
const stderr = commandOutput.stderr.trim();
210+
const stdout = commandOutput.stdout.replace(/\n$/, "");
211+
const stderr = commandOutput.stderr.replace(/\n$/, "");
211212
let items: string[] = [];
212213

213214
if (("stdout" == this.args.stdio) || ("both" == this.args.stdio)) {
@@ -218,10 +219,12 @@ export class CommandHandler {
218219
items.push(...stderr.split(this.EOL));
219220
}
220221

221-
items = items.filter(item => item !== "");
222+
if (this.args.filterEmptyResults) {
223+
items = items.filter(item => item !== "");
224+
}
222225

223226
if ((items.length == 0) && (undefined === this.args.defaultOptions)) {
224-
let msg = `The command for input '${this.input.id}' returned empty result.`;
227+
let msg = `The command for input '${this.input.id}' didn't output any results.`;
225228

226229
if (stderr) {
227230
msg += ` stderr: '${stderr}'`;
@@ -246,8 +249,7 @@ export class CommandHandler {
246249
description: values[2],
247250
detail: values[3],
248251
};
249-
})
250-
.filter((item: QuickPickItem) => item.label && item.label.trim().length > 0);
252+
});
251253
}
252254

253255
protected getDefault() {

src/lib/ShellCommandOptions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export interface ShellCommandOptions
1212
allowCustomValues?: boolean;
1313
multiselect?: boolean;
1414
warnOnStderr?: boolean;
15+
filterEmptyResults?: boolean;
1516
multiselectSeparator?: string;
1617
fieldSeparator?: string;
1718
description?: string;

0 commit comments

Comments
 (0)