Skip to content

London | 26-SDC-July | Alex Jamshidi | Sprint 3 | Implement shell tools - #635

Open
Alex-Jamshidi wants to merge 15 commits into
CodeYourFuture:mainfrom
Alex-Jamshidi:implement-shell-tools
Open

London | 26-SDC-July | Alex Jamshidi | Sprint 3 | Implement shell tools #635
Alex-Jamshidi wants to merge 15 commits into
CodeYourFuture:mainfrom
Alex-Jamshidi:implement-shell-tools

Conversation

@Alex-Jamshidi

@Alex-Jamshidi Alex-Jamshidi commented Jul 30, 2026

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

cat
Handles all commands correctly:
cat sample-files/1.txt
cat -n sample-files/1.txt
cat sample-files/.txt
cat -n sample-files/.txt
cat -b sample-files/3.txt

Stretch:
Handles multiple flags and incorrect flags
(although does not parse b and n correctly when used together)

wc
Handles all commands correctly:
wc sample-files/*
wc -l sample-files/3.txt
wc -w sample-files/3.txt
wc -c sample-files/3.txt
wc -l sample-files/*
wc -w -l sample-files/3.txt
wc -w -l sample-files/*

Stretch:
Handles multiple flags and incorrect flags
Handles flag order

ls
Handles all commands correctly:
ls sample-files
ls sample-files/1.txt
ls sample-files/
ls -1
ls -1 sample-files
ls -1 -a sample-files

Stretch
Handles multiple flags and incorrect flags
Handles flag order

Task ID: CYF-1150

@Alex-Jamshidi Alex-Jamshidi 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 Jul 30, 2026
@LonMcGregor LonMcGregor added the Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. label Aug 4, 2026

@LonMcGregor LonMcGregor left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good start but there is quite a bit of work still to do.

You've built your own argument handling system. Is your way of handling options/arguments always going to be the best? Is there a better way of doing this?

Comment thread implement-shell-tools/cat/cat.js Outdated
function bFlag() {
return allFilesContents.map((fileContent) => {
let lineNumber = 1;
return fileContent.map((line, index) => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A map is typically used to change one array into another using a function that doesn't have side effects. Here, you are changing a lineNumber variable each time the map runs. This isn't wrong, but just be careful of side effects, especially if you ever want to run things asynchronously.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I see - I have refactored my code, so now I use a foreach to mutate the original array rather than mapping a new one.

Comment thread implement-shell-tools/ls/ls.js Outdated

function Flag1() {
if (printInList) {
outputString = outputString.replaceAll("\t", "\n");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I like that you are using lots of task specific functions.

But, is using global variables in this way a safe way of programming this? Is there a way that would have the data flow through your app in a more semantic way?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I have rewritten many of the functions to allow the data to flow through, rather than the functions independently manipulating data stored in global variables.

Comment thread implement-shell-tools/ls/ls.js Outdated
}

function print() {
if (printInList == true) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Think about how if conditions work, and check this line again. Are you writing code in the most optimal way?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

ah yes, I see - updated

Comment thread implement-shell-tools/wc/wc.js Outdated
}

function deleteOutputs() {
if (!deleted) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you explain your thinking that led to a design where you need to manually handle your resources like this?

@Alex-Jamshidi Alex-Jamshidi Aug 28, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I think it was a little convoluted...

Given no flags displays all data, but the presence of any flags means only the flagged data is displayed.
I decided that if any flag was given: all data should be deleted and just the data for that flag added back in.

This would be the same for all flags.

I've decided to create a separate array which lists displayed metrics from flags to simplify this.

I've also refactored a lot.

@LonMcGregor LonMcGregor 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. Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. labels Aug 4, 2026
@Alex-Jamshidi

Copy link
Copy Markdown
Author

Good start but there is quite a bit of work still to do.

You've built your own argument handling system. Is your way of handling options/arguments always going to be the best? Is there a better way of doing this?

By which I assume you mean using the commander library? Yes this would be simpler to write and an ultimately more effective way to handle things

@Alex-Jamshidi Alex-Jamshidi added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Aug 28, 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. Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. 📅 Sprint 3 Assigned during Sprint 3 of this module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants