Skip to content

Commit bdfbbba

Browse files
committed
print totals in bottom row if more than one file
1 parent 1a80d5b commit bdfbbba

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

  • implement-shell-tools/wc

implement-shell-tools/wc/wc.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@ if (Object.keys(options).length === 0) {
2727
// incrementally updated in the loop below
2828
const totals = { l: 0, w: 0, c: 0 };
2929

30+
let fileCount = 0;
3031
for (const path of paths) {
3132
if (fs.statSync(path).isDirectory()) {
3233
console.log(`wc: ${path}: read: Is a directory`);
3334
} else {
35+
fileCount++;
3436
let outputStr = "";
3537
const file = fs.readFileSync(path, "utf-8");
3638
if (options.l) {
@@ -63,3 +65,7 @@ for (const path of paths) {
6365
console.log(outputStr);
6466
}
6567
}
68+
69+
if (fileCount > 1) {
70+
console.log(`\t${totals.l}\t${totals.w}\t${totals.c} total`);
71+
}

0 commit comments

Comments
 (0)