Skip to content

Commit 6f8863e

Browse files
committed
refactor: extract duplicated formatCliOutput to util.ts
formatPatchloomOutput (quickActions.ts) and formatBatchOutput (batchApply.ts) were identical. Extract to shared formatCliOutput in util.ts and delegate from both call sites. Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
1 parent f490363 commit 6f8863e

3 files changed

Lines changed: 13 additions & 13 deletions

File tree

src/commands/batchApply.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { execFile } from "node:child_process";
22
import type * as VSCode from "vscode";
33
import { patchloomNeedsUpgrade, resolvePatchloomStatus } from "../binary/patchloom.js";
4+
import { formatCliOutput } from "../util.js";
45
import { getPatchloomLog } from "../logging/outputChannel.js";
56
import { activeWorkspaceFolder } from "../workspace/readiness.js";
67

@@ -135,10 +136,5 @@ function executePatchloomWithStdin(
135136
}
136137

137138
function formatBatchOutput(result: BatchCommandResult): string {
138-
const output = `${result.stderr}\n${result.stdout}`
139-
.split(/\r?\n/)
140-
.map((line) => line.trim())
141-
.filter((line) => line.length > 0)
142-
.join(" ");
143-
return output || `exit code ${result.exitCode}`;
139+
return formatCliOutput(result);
144140
}

src/commands/quickActions.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { promisify } from "node:util";
66
import type * as VSCode from "vscode";
77
import { patchloomNeedsUpgrade, resolvePatchloomStatus } from "../binary/patchloom.js";
88
import { getPatchloomLog } from "../logging/outputChannel.js";
9-
import { formatError } from "../util.js";
9+
import { formatCliOutput, formatError } from "../util.js";
1010
import { activeWorkspaceFolder, describeWorkspaceEnvironment } from "../workspace/readiness.js";
1111

1212
const execFileAsync = promisify(execFile);
@@ -641,12 +641,7 @@ async function executePatchloom(
641641
}
642642

643643
function formatPatchloomOutput(result: PatchloomCommandResult): string {
644-
const output = `${result.stderr}\n${result.stdout}`
645-
.split(/\r?\n/)
646-
.map((line) => line.trim())
647-
.filter((line) => line.length > 0)
648-
.join(" ");
649-
return output || `exit code ${result.exitCode}`;
644+
return formatCliOutput(result);
650645
}
651646

652647
function sameFilePath(left: string, right: string): boolean {

src/util.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,13 @@ export function formatError(error: unknown): string {
33
return error.message;
44
}
55
return String(error);
6+
}
7+
8+
export function formatCliOutput(result: { exitCode: number; stdout: string; stderr: string }): string {
9+
const output = `${result.stderr}\n${result.stdout}`
10+
.split(/\r?\n/)
11+
.map((line) => line.trim())
12+
.filter((line) => line.length > 0)
13+
.join(" ");
14+
return output || `exit code ${result.exitCode}`;
615
}

0 commit comments

Comments
 (0)