Skip to content

West Midlands | 26 March SDC | Iswat Bello | Sprint 3 | implement shell tools#454

Open
Iswanna wants to merge 7 commits intoCodeYourFuture:mainfrom
Iswanna:tools/sprint3-implement-shell-tools
Open

West Midlands | 26 March SDC | Iswat Bello | Sprint 3 | implement shell tools#454
Iswanna wants to merge 7 commits intoCodeYourFuture:mainfrom
Iswanna:tools/sprint3-implement-shell-tools

Conversation

@Iswanna
Copy link
Copy Markdown

@Iswanna Iswanna commented Apr 1, 2026

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

This PR implements the cat, ls, and wc Unix utilities in Node.js using ECMAScript Modules and Commander.js for CLI parsing.
All implementations feature asynchronous file operations, robust error handling, and aligned output formatting.

Iswanna added 7 commits March 30, 2026 21:20
Add cat/cat.js which reads a file path from argv and prints the file contents
using node fs promises and top-level await. Logs argv and path (debug output).
- Refactor to async readMultipleFiles() function
- Support reading multiple files via Promise.all
- Output concatenated file contents to stdout
- Add error handling with exit code 1 on failure
- Remove debug logging (argv, path)
- Fix markdown list formatting in README (bullets)
- Replace manual argv parsing with commander.js for robust CLI handling
- Add -n/--number flag to number all output lines
- Add -b/--number-nonblank flag to number only non-empty lines
- Refactor variable names for clarity (filePathsToRead, concatenatedContent, etc)
- Improve error handling with process.exitCode = 1
- Remove debug logging
- Add ls/ls.js: reads a directory, supports -1 (one-per-line) and -a (include dotfiles)
- Use commander for CLI flags, fs.promises.readdir for reading directories
- Add error handling and set non-zero exit code on failure
- docs(ls): normalize README bullets so example commands render correctly
- Add wc/wc.js: reads files and outputs line, word, and byte counts
- Support multiple files with totals row
- Use fs.promises.readFile for async file reading
- Add error handling for missing files with non-zero exit code
- Format output to match standard wc utility (padded columns)
- docs(wc): normalize README bullets so example commands render correctly
- Migrate from manual argv parsing to commander.js for robust flag handling
- Add support for -l (lines), -w (words), -c (bytes) flags
- Refactor calculateFileStats to return object with descriptive properties
- Rename printFormattedLine to printReport for clarity
- Improve flag detection: default to all columns when no flags provided
- Maintain totals row for multiple files
- Update error messages to match standard wc format
- Clean up JSDoc comments and code structure
- Rename parameters and variables for better descriptiveness:
  - files → filePaths
  - showAll → shouldShowAllStats
  - results → allFileStats
  - stats → fileStats
  - totals → grandTotals
  - label → displayName
  - s → stat (in reduce callbacks)
  - w → word (in filter callback)
  - output → outputColumns
  - format → formatColumn
  - printReport → printFormattedReport

- Extract inline calculations to named variables in calculateFileStats()
  - lines, words, bytes for improved readability

- Maintain all functionality and test coverage
- No behavioral changes, purely refactoring for clarity
@Iswanna Iswanna 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 1, 2026
@nedssoft nedssoft 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 Apr 11, 2026
Comment on lines +14 to +16
.action(async (filePaths, options) => {
const noFlagsProvided = !options.lines && !options.words && !options.bytes;
const showAll = noFlagsProvided;
const shouldShowAllStats = noFlagsProvided;
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 variable noFlagsProvided appears a bit redundant. Do you think using shouldShowAllStats in line 15 wouldn't give the same clarity?

Comment on lines 61 to 65
if (showAll || options.bytes) output.push(format(stats.byteCount));
if (shouldShowAllStats || options.lines) outputColumns.push(formatColumn(stats.lineCount));
if (shouldShowAllStats || options.words) outputColumns.push(formatColumn(stats.wordCount));
if (shouldShowAllStats || options.bytes) outputColumns.push(formatColumn(stats.byteCount));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Consider handling the shouldShowAllStats in one block to minimise the repetition. If the shouldShowAllStats condition kicks in, the program should not need to bother about other cases.

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. Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. 📅 Sprint 3 Assigned during Sprint 3 of this module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants