Skip to content

Commit 4902edc

Browse files
Refactor command options in program args for clarity and update options names in printWcOutput function accordingly
1 parent fafae17 commit 4902edc

File tree

1 file changed

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

1 file changed

+10
-10
lines changed

implement-shell-tools/wc/wc.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ program
77
.name("wc")
88
.description("An alternative to the 'wc' command")
99
.argument("<files...>", "The file(s) to count lines/words/bytes")
10-
.option("-l", "--lines", "Print the newline counts")
11-
.option("-w", "--words", "Print the word counts")
12-
.option("-c", "--bytes", "Print the byte counts")
10+
.option("-l, --lines", "Print the newline counts")
11+
.option("-w, --words", "Print the word counts")
12+
.option("-c, --bytes", "Print the byte counts")
1313
.action(async (files, options) => {
1414
try {
1515
// call newWc for all files
@@ -32,20 +32,20 @@ function formatCount(count) {
3232
function printWcOutput(lineCount, wordCount, byteCount, file, options, noFlags) {
3333
const parts = [];
3434

35-
if (noFlags || options.l) parts.push(formatCount(lineCount));
36-
if (noFlags || options.w) parts.push(formatCount(wordCount));
37-
if (noFlags || options.c) parts.push(formatCount(byteCount));
38-
35+
if (noFlags || options.lines) parts.push(formatCount(lineCount));
36+
if (noFlags || options.words) parts.push(formatCount(wordCount));
37+
if (noFlags || options.bytes) parts.push(formatCount(byteCount));
38+
3939
parts.push(file);
4040
console.log(parts.join(" "));
4141
}
4242

4343
async function newWc(files, options) {
4444

4545
const noFlags =
46-
!options.l &&
47-
!options.w &&
48-
!options.c;
46+
!options.lines &&
47+
!options.words &&
48+
!options.bytes;
4949

5050
// set the counts variables
5151
let totalLines = 0;

0 commit comments

Comments
 (0)