Skip to content

Commit d93df02

Browse files
committed
covers readme file
1 parent 22e428e commit d93df02

File tree

1 file changed

+8
-0
lines changed
  • implement-shell-tools/cat

1 file changed

+8
-0
lines changed

implement-shell-tools/cat/cat.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ function printFile(filePath, options) {
88
const content = fs.readFileSync(filePath, "utf-8");
99
const lines = content.split("\n");
1010

11+
if (lines.length && lines[lines.length - 1] === "") {
12+
lines.pop();
13+
}
14+
1115
lines.forEach((line) => {
1216
let prefix = "";
1317

@@ -24,6 +28,7 @@ function printFile(filePath, options) {
2428
});
2529
} catch (error) {
2630
console.error(`cat: ${filePath}: ${error.message}`);
31+
process.exitCode = 1;
2732
}
2833
}
2934

@@ -51,6 +56,9 @@ function main() {
5156
}
5257

5358
files.forEach((file) => {
59+
if(options.numberMode) {
60+
globalLineCounter = 1; //reset line counter for each file if numbering is enabled
61+
}
5462
printFile(file, options);
5563
});
5664
}

0 commit comments

Comments
 (0)