generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 76
London | 25-SDC-Nov | Aida Eslamimoghadam | Sprint 3 | Implement Shell Tools #249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
aydaeslami
wants to merge
8
commits into
CodeYourFuture:main
Choose a base branch
from
aydaeslami:ImplementShellTools
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f929943
Create basic mycat.js
aydaeslami 2691eee
Changed basic and addedn flan -n and -b
aydaeslami 176b4d5
Ls
aydaeslami 9f8b68c
My Wc
aydaeslami 66e8b67
Edit myCat
aydaeslami 830d197
Delete repetition lines
aydaeslami 1160111
Change param
aydaeslami b6fdd20
Edit and removed unnecessary lines.
aydaeslami File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,4 @@ | ||
| node_modules | ||
| .DS_Store | ||
| __pycache__/ | ||
| *.pyc |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import { program } from "commander"; | ||
| import { promises as fs } from "node:fs"; | ||
|
|
||
| program | ||
| .name("myCat") | ||
| .description("Simple file viewer") | ||
| .option("-n", "Number all output lines") | ||
| .option("-b", "Number non-blank output lines") | ||
| .argument("<path...>", "One or more file paths to show"); | ||
|
|
||
| program.parse(); | ||
|
|
||
| const files = program.args; | ||
| const opts = program.opts(); | ||
| let lineNumber = 1; | ||
|
|
||
| for (const filename of files) { | ||
| const content = await fs.readFile(filename, "utf-8"); | ||
| const lines = content.split("\n"); | ||
|
|
||
| if (opts.n) { | ||
|
|
||
| for (const line of lines) { | ||
| console.log(lineNumber + " " + line); | ||
| lineNumber++; | ||
| } | ||
| } else if (opts.b) { | ||
|
|
||
| for (const line of lines) { | ||
| if (line.trim() !== "") { | ||
| console.log(lineNumber + " " + line); | ||
| lineNumber++; | ||
| } | ||
| } | ||
| } else { | ||
| console.log(content); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import { program } from "commander"; | ||
| import { promises as fs } from "node:fs"; | ||
|
|
||
| program | ||
| .name("myLs") | ||
| .description("my ls clone") | ||
| .option("-1, --one-per-line", "one entry per line") | ||
| .option("-a", "show hidden files") | ||
| .argument("[paths...]", "file or directory paths"); | ||
LonMcGregor marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| program.parse(); | ||
|
|
||
| const opts = program.opts(); | ||
| let paths = program.args; | ||
|
|
||
| if (paths.length === 0) { | ||
| paths = ["."]; | ||
| } | ||
|
|
||
| for (const path of paths) { | ||
| const directoryItems = await fs.readdir(path); | ||
|
|
||
| for (const file of directoryItems) { | ||
| if (!opts.a && file.startsWith(".")) { | ||
| continue; | ||
| } | ||
|
|
||
| if (opts.onePerLine) { | ||
| console.log(file); | ||
| } else { | ||
| console.log(file + " "); | ||
| } | ||
| } | ||
|
|
||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "type": "module", | ||
| "dependencies": { | ||
| "commander": "^14.0.2" | ||
| } | ||
| } |
LonMcGregor marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import { program } from "commander"; | ||
| import { promises as fs } from "node:fs"; | ||
|
|
||
| program | ||
| .name("myWc") | ||
| .description("my wc clone") | ||
| .option("-l", "line count") | ||
| .option("-w", "words count") | ||
| .option("-c", "character count") | ||
| .option("-s", "character count without spaces") | ||
| .argument("[paths...]", "file or directory paths"); | ||
|
|
||
| program.parse(); | ||
|
|
||
| const opts = program.opts(); | ||
| let files = program.args; | ||
|
|
||
| if (files.length === 0) { | ||
| files = ["."]; | ||
| } | ||
|
|
||
| let totalLines = 0; | ||
| let totalWords = 0; | ||
|
|
||
| if (opts.l) { | ||
| for (const file of files) { | ||
| const content = await fs.readFile(file, "utf-8"); | ||
| const lineCount = content.split("\n").length; | ||
|
|
||
| totalLines += lineCount; | ||
| } | ||
| console.log("Lines:", totalLines); | ||
| } | ||
| if (opts.w) { | ||
| for (const file of files) { | ||
| const content = await fs.readFile(file, "utf-8"); | ||
|
|
||
| const wordCount = content.trim().split(/\s+/).length; | ||
| totalWords += wordCount; | ||
| } | ||
| console.log("Total words:", totalWords); | ||
| } | ||
| if (opts.c) { | ||
| let totalChars = 0; | ||
| for (const file of files) { | ||
| const content = await fs.readFile(file, "utf-8"); | ||
|
|
||
| totalChars += content.trim().length; | ||
|
|
||
| } | ||
| console.log("Total characters:", totalChars); | ||
| } | ||
|
|
||
| if (opts.s) { | ||
| let totalCharsNoSpaces = 0; | ||
| for (const file of files) { | ||
| const content = await fs.readFile(file, "utf-8"); | ||
| const withoutSpaces = content.replace(/\s/g, ""); | ||
| totalCharsNoSpaces += withoutSpaces.length; | ||
| } | ||
| console.log("Total characters without spaces:", totalCharsNoSpaces); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.