Skip to content

London | 26-SDC-Mar | Beko | Sprint 3 | Implement Shell Tools#500

Open
Abubakar-Meigag wants to merge 1 commit into
CodeYourFuture:mainfrom
Abubakar-Meigag:beko-Implement-shell-tools
Open

London | 26-SDC-Mar | Beko | Sprint 3 | Implement Shell Tools#500
Abubakar-Meigag wants to merge 1 commit into
CodeYourFuture:mainfrom
Abubakar-Meigag:beko-Implement-shell-tools

Conversation

@Abubakar-Meigag
Copy link
Copy Markdown
Contributor

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

Complete shell tools for sprint 3

@Abubakar-Meigag Abubakar-Meigag added 📅 Sprint 3 Assigned during Sprint 3 of this module Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Module-Tools The name of the module. labels Apr 17, 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.

I've got several notes from my side, could you fix them please? Otherwise good job

if (lines[lines.length - 1] === '') lines.pop();

for (const line of lines) {
const isBlank = line.trim() === '';
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

real cat treats lines with spaces as real lines and does not ignore them

content = await fs.readFile(filePath, 'utf8');
} catch {
console.error(`cat: ${filePath}: No file or directory exists`);
process.exit(1);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This will stop processing of other files. Real cat continues processing of other files.


const targetDir = paths[0] ?? '.';

const entries = await fs.readdir(targetDir);
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 happens if no dir is found?

const result = showAll ? ['.', '..', ...entries] : entries.filter(e => !e.startsWith('.'));

for (const entry of result) {
console.log(entry);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Real ls default output is space-separated on one line; one-per-line requires the -1 flag. This always uses one-per-line regardless. The -1 flag needs to be implemented and the default output should join entries with spaces (plus a trailing newline).


const targetDir = paths[0] ?? '.';

const entries = await fs.readdir(targetDir);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

entries is not sorted. readdir order is filesystem-dependent. Sort before output: entries.sort(). The . and .. entries should remain first.


const showAll = dash.includes('-a');

const targetDir = paths[0] ?? '.';
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 have multiple paths?

totalWords += words;
totalBytes += bytes;

if (forLines) {
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 happens if we have several flags simultaneously?

content = await fs.readFile(filePath, 'utf8');
} catch {
console.error(`wc: ${filePath}: No file or directory exists`);
process.exit(1);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Same situation: if one file is problematic, the whole execution stops. Real wc continues processing of other files.

}

if (filePaths.length > 1) {
if (forLines) {
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 have several flags passed?

@SlideGauge SlideGauge added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels May 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Module-Tools The name of the module. Reviewed Volunteer to add when completing a review with trainee action still to take. 📅 Sprint 3 Assigned during Sprint 3 of this module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants