Skip to content

Commit d2e94fc

Browse files
committed
Support multiple files in wc
1 parent 4e1c717 commit d2e94fc

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

  • implement-shell-tools/wc

implement-shell-tools/wc/wc.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ import { promises as fs } from "node:fs";
33

44
const args = process.argv.slice(2);
55

6-
const path = args[0];
7-
8-
if (!path) {
9-
console.error("Please provide a file path");
6+
if (args.length === 0) {
7+
console.error("Please provide at least one file");
108
process.exit(1);
119
}
1210

13-
const content = await fs.readFile(path, "utf-8");
11+
for (const path of args) {
12+
const content = await fs.readFile(path, "utf-8");
1413

15-
const lines = content.split("\n").length;
16-
const words = content.split(" ").length;
17-
const chars = content.length;
14+
const lines = content.split("\n").length;
15+
const words = content.split(" ").length;
16+
const chars = content.length;
1817

19-
console.log(lines, words, chars);
18+
console.log(lines, words, chars, path);
19+
}

0 commit comments

Comments
 (0)