Skip to content

NW | 2026-MAR-SDC | Ahmad Hmedan | Sprint 3 | Implement shell tool#452

Open
AhmadHmedann wants to merge 13 commits into
CodeYourFuture:mainfrom
AhmadHmedann:implement-shell-tools
Open

NW | 2026-MAR-SDC | Ahmad Hmedan | Sprint 3 | Implement shell tool#452
AhmadHmedann wants to merge 13 commits into
CodeYourFuture:mainfrom
AhmadHmedann:implement-shell-tools

Conversation

@AhmadHmedann
Copy link
Copy Markdown

Learners, PR Template

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

Changelist

Implementation of cat, ls , and wc with support of require flag and multiple files.

Questions

Should I wrap each file operation in its own try–catch inside the loop, or use a single try–catch around the whole loop when processing multiple paths?

@AhmadHmedann AhmadHmedann added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Apr 1, 2026
@SlideGauge SlideGauge added Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels May 19, 2026
Copy link
Copy Markdown

@SlideGauge SlideGauge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work, I have several notes from my side, implement them please.

try {
const content = await fs.readFile(path, "utf-8");
if(options.b)
{
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is javascript convention for braces placement?
do we place opening curly brace on the same line as the statement or not?

const content = await fs.readFile(path, "utf-8");
if(options.b)
{
const lines = content.split("\n");
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you align the column on this line?

let lineNumber = 1;

for (const path of paths) {
try {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good use of try catch

for (const path of paths) {
try {
const content = await fs.readFile(path, "utf-8");
if(options.b)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we decrease the complexity of the logic (amount of nested blocks) by extracting all the output logic into a separate function?

.name("ls ")
.description("ls implementation")
.argument("[path]", "The path to process")
.option("-1, --one-per-line", "one file per line")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have logic processing this parameter?

};


try {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the existing wc would continue execution if there was single error handling a single file, could we do the same here? (Just in case, cat.mjs does it)

const content = await fs.readFile(path, "utf-8");

const linesCounter = content.split("\n").length - 1;
const wordsCounter = content.trim().split(/\s+/).length;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what will happen with wordsCounter if the file content is empty?

process.stdout.write(content);
}
} catch (error) {
console.error(error.message);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What will return real cat if at least one file had errors during processing?

}

for (const line of lines) {
process.stdout.write(` ${lineNumber} ${line}\n`);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default, cat -n right-justifies the line number in a 6-character-wide field, followed by a tab.

@SlideGauge SlideGauge added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. labels May 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Reviewed Volunteer to add when completing a review with trainee action still to take.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants