Skip to content

Commit 5e48487

Browse files
committed
flag fixed
1 parent f8ea271 commit 5e48487

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

implement-shell-tools/cat/index.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
1-
import { promises as fs } from "node:fs";
1+
import { readFileSync } from "node:fs";
22

3-
async function cleanInput(listOfFiles) {
3+
function cleanInput(listOfFiles) {
44
let cleanLinesArr = [];
5+
56
for (const file of listOfFiles) {
6-
const grabbedText = await fs.readFile(file, "utf-8");
7+
const grabbedText = readFileSync(file, "utf-8");
78
const splitLines = grabbedText.split("\n");
89
cleanLinesArr.push(...splitLines);
910
}
1011
return cleanLinesArr;
1112
}
1213

14+
const args = process.argv.slice(2);
15+
let flag;
16+
let restIsFiles;
17+
18+
if (args[0] && args[0][0] === "-") {
19+
flag = args[0];
20+
restIsFiles = args.slice(1);
21+
} else {
22+
flag = null;
23+
restIsFiles = args;
24+
}
25+
1326
function takeSpecifiedAction(cleanLinesArr, flag) {
1427
let countingOnlyFullLines = 1;
1528

@@ -32,3 +45,6 @@ function takeSpecifiedAction(cleanLinesArr, flag) {
3245
}
3346
}
3447
}
48+
49+
const lines = cleanInput(restIsFiles);
50+
takeSpecifiedAction(lines, flag);

0 commit comments

Comments
 (0)