Skip to content

Commit a28e72e

Browse files
committed
fix: Set the process exit code to 1 if any file fails.
1 parent a759353 commit a28e72e

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

‎implement-shell-tools/cat/cat.mjs‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { promises as fs } from "node:fs";
1+
import { promises as fs } from "node:fs";
22
import { program } from "commander";
33

44
program
@@ -13,7 +13,7 @@ const paths = program.args;
1313
const options = program.opts();
1414

1515
let lineNumber = 1;
16-
16+
let hadError = false;
1717
for (const path of paths) {
1818
try {
1919
const content = await fs.readFile(path, "utf-8");
@@ -39,13 +39,17 @@ for (const path of paths) {
3939
}
4040

4141
for (const line of lines) {
42-
process.stdout.write(` ${lineNumber} ${line}\n`);
42+
process.stdout.write(`${String(lineNumber).padStart(6)}\t ${line}\n`);
4343
lineNumber++;
4444
}
4545
} else {
4646
process.stdout.write(content);
4747
}
4848
} catch (error) {
4949
console.error(error.message);
50+
hadError = true;
5051
}
5152
}
53+
if (hadError) {
54+
process.exitCode = 1;
55+
}

0 commit comments

Comments
 (0)