NW | 2026-mar-sdc | Zabihollah Namazi | Sprint 3 | implement shell tools#442
Conversation
SlideGauge
left a comment
There was a problem hiding this comment.
There are several notes from me, could you address them please?
| } | ||
| } else if (showAllNumbers) { | ||
| // -n: number all lines | ||
| console.log(`${lineNumber} ${line}`); |
There was a problem hiding this comment.
Does it reproduce the same formatting the real cat does?
| lines.forEach((line) => { | ||
| if (showNonEmptyNumbers) { | ||
| // -b: number only non-empty lines | ||
| if (line.trim() !== "") { |
There was a problem hiding this comment.
real cat considers a line with whitespaces to be non-empty line
There was a problem hiding this comment.
Updated it with if (line !== "")
| for (const path of paths) { | ||
| try { | ||
| // read file as text | ||
| const content = await fs.readFile(path, "utf-8"); |
There was a problem hiding this comment.
Does the whole algorithm place a trailing new line by the end of the file?
There was a problem hiding this comment.
Currently the implementation prints using console.log, so it always appends a newline after output
| console.log(element) | ||
| }); | ||
| } | ||
|
|
There was a problem hiding this comment.
What does real ls do if no command-line arguments are passed?
There was a problem hiding this comment.
I’ve updated the implementation so the default behaviour now properly handles this and filters hidden files unless -a is passed
| const direc = await fs.readdir(path) | ||
| // if the path is <sample-files> console.log(direc) gives us =>: [ '.hidden.txt', '1.txt', '2.txt', '3.txt', 'dir' ] | ||
|
|
||
| if(showOnePerLine && showAllFilesWithHidden){ |
There was a problem hiding this comment.
Yes, Ive now separated -a and -1 so they work independently like real ls. -a controls visibility of hidden files, and -1 controls output format
| const paths = args.filter(arg => !arg.startsWith("-")) || "."; | ||
| console.log(paths) | ||
|
|
||
| // const direct = await fs.readdir(path); |
| let totalWords = 0; | ||
| let totalchars = 0; | ||
|
|
||
| if(showLines){ |
There was a problem hiding this comment.
Does this else if logic support multiflag execution?
There was a problem hiding this comment.
Yes, you’re right — I changed it to support multiple flags by using separate if conditions instead of else if
|
|
||
| if(showLines){ | ||
| for (const path of paths){ | ||
| const content = await fs.readFile(path, "utf-8"); |
There was a problem hiding this comment.
What will happen if file is absent?
There was a problem hiding this comment.
updated the code , now , If a file is missing, program prints an error and keeps running for the remaining files
| totalWords += words; | ||
| totalchars += char; | ||
| } | ||
| console.log("lines: ", totalLines, " words", totalWords, " char:", totalchars) |
| totalWords += words; | ||
| totalchars += char; | ||
| } | ||
| console.log("lines: ", totalLines, " words", totalWords, " char:", totalchars) |
There was a problem hiding this comment.
Real wc does not write "lines: ", "wods" and so on, instead, it right-aligns numbers and uses tab
Self checklist
Changelist
hi
could you please check the answers? thanks