Skip to content

Glasgow | 26- SDC-Mar | Taras Mykytiuk | Sprint 3 | Implement shell tools#447

Open
TarasMykytiuk wants to merge 3 commits into
CodeYourFuture:mainfrom
TarasMykytiuk:implement_shell_tools
Open

Glasgow | 26- SDC-Mar | Taras Mykytiuk | Sprint 3 | Implement shell tools#447
TarasMykytiuk wants to merge 3 commits into
CodeYourFuture:mainfrom
TarasMykytiuk:implement_shell_tools

Conversation

@TarasMykytiuk
Copy link
Copy Markdown

@TarasMykytiuk TarasMykytiuk commented Mar 31, 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

Implement shell tools exercises completed.

@TarasMykytiuk TarasMykytiuk 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 Mar 31, 2026
@github-actions

This comment has been minimized.

@github-actions github-actions Bot removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Mar 31, 2026
@TarasMykytiuk TarasMykytiuk added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Mar 31, 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 30, 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.

Could you address my comments please?

async function displayFiles(paths, flags) {
let content = '';
for (let i = 0; i < paths.length; i++) {
content += await fs.readFile(paths[i], "utf-8");
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 can't open one of the files?

(flags.includes("-n") && !flags.includes("-b")) ||
(flags.includes("-b") && lines[i] != "")
) {
output = " " + (lineNumber).toString() + " " + lines[i];
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Here we always prepend 5 spaces. But we need to right-align into a fixed-width field. (So numbers like 10, 100 etc does not shift the column

(flags.includes("-n") && !flags.includes("-b")) ||
(flags.includes("-b") && lines[i] != "")
) {
output = " " + (lineNumber).toString() + " " + lines[i];
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 uses tab separator between number and lines

let output = lines[i];
if (
(flags.includes("-n") && !flags.includes("-b")) ||
(flags.includes("-b") && lines[i] != "")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

shouldn't we use strict inequality in javascript?

for (const fileName of files) {
let fileOutput = '';
let filePath = dir + "/" + fileName;
let file = await fs.readFile(filePath, "utf-8");
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 if the file does not exist?

let ending = '';
for (let i = 0; i < argv.length; i++) {
if (argv[i][0] == "-") {
flag = argv[i];
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 flags passed?

let file = await fs.readFile(filePath, "utf-8");
let linesNum = countLinesInString(file);
let wordsNum = countWordsInString(file);
let bytes = file.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 length if the file has non ASCII characters?

let fileOutput = '';
let filePath = dir + "/" + fileName;
let file = await fs.readFile(filePath, "utf-8");
let linesNum = countLinesInString(file);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

we do not reassign let- variables here, so we should use const instead

}
}

function countLinesInString(str) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

like for splitting logic intot functions

}

function countWordsInString(str) {
let words = str.replace(/\n/g, ' ').split(' ');
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 need to take tabs and other whitespace into account?

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