Skip to content

Commit c32410a

Browse files
committed
flesh out logic to include the -w & -c options
1 parent 009c40b commit c32410a

File tree

1 file changed

+10
-3
lines changed
  • implement-shell-tools/wc

1 file changed

+10
-3
lines changed

implement-shell-tools/wc/wc.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ program
88
.description("Counts lines, words or characters in a file (or all files) inside a directory")
99
.option("-l, --line", "The number of lines in each file")
1010
.option("-w, --word", "The number of words in each file")
11+
.option("-c, --character", "The number of characters in each file")
1112
.argument("<path...>", "The file path to process");
1213

1314
program.parse();
@@ -44,8 +45,10 @@ if (pathInfo.isFile()) {
4445
const stats = counter(content);
4546
if (options.line) {
4647
console.log(`${stats.lines} ${path}`);
48+
} else if (options.word) {
49+
console.log(`${stats.words} ${path}`);
4750
} else {
48-
console.log(`${stats.lines} ${stats.words} ${stats.characters} ${path}`);
51+
console.log(`${stats.characters} ${path}`);
4952
}
5053

5154
totalLines += stats.lines;
@@ -62,8 +65,10 @@ if (pathInfo.isFile()) {
6265

6366
if (options.line) {
6467
console.log(`${stats.lines} ${filePath}`);
68+
} else if (options.word) {
69+
console.log(`${stats.words} ${filePath}`);
6570
} else {
66-
console.log(`${stats.lines} ${stats.words} ${stats.characters} ${filePath}`);
71+
console.log(`${stats.characters} ${filePath}`);
6772
}
6873

6974
totalLines += stats.lines;
@@ -78,7 +83,9 @@ if (pathInfo.isFile()) {
7883
if (fileCount > 1) {
7984
if (options.line) {
8085
console.log(`${totalLines} total`);
86+
} else if (options.word) {
87+
console.log(`${totalWords} total`);
8188
} else {
82-
console.log(`${totalLines} ${totalWords} ${totalCharacters} total`);
89+
console.log(`${totalCharacters} total`);
8390
}
8491
}

0 commit comments

Comments
 (0)