Skip to content

Commit eb67a84

Browse files
committed
update logic to handl having mutple paths (files) when dealing with a dir
1 parent c58db9c commit eb67a84

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

  • implement-shell-tools/wc

implement-shell-tools/wc/wc.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@ program.parse();
1414
const argv = program.args;
1515

1616

17-
1817
const path = argv[0];
1918

2019
const options = program.opts();
2120

2221

23-
const pathInfo = await stat(path);
22+
23+
if (argv.length < 1) {
24+
console.error("You must pass at least one path!");
25+
process.exit(1);
26+
}
2427

2528
function counter(item) {
2629
const lines = item.trim().split("\n").length;
@@ -29,6 +32,9 @@ function counter(item) {
2932
return { lines, words, characters };
3033
}
3134

35+
for (const path of argv) {
36+
const pathInfo = await stat(path);
37+
3238
if (pathInfo.isFile()) {
3339
const content = await fs.readFile(path, "utf-8");
3440
const stats = counter(content);
@@ -52,3 +58,4 @@ if (pathInfo.isFile()) {
5258
}
5359
}
5460

61+
}

0 commit comments

Comments
 (0)