generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 42
Sheffield | 25-SDC-Nov | Sheida Shabankari | Sprint 3 |Implement shell tools #241
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
sheida-shab
wants to merge
17
commits into
CodeYourFuture:main
Choose a base branch
from
sheida-shab:implement-shell-tools
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.
+144
−0
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
0ac00bc
implement basic cat command
sheida-shab b640def
implementing wild cards pattern
sheida-shab cb08903
fixing the sort bug
sheida-shab dfc9d45
implementing flag -n
sheida-shab 4aceacf
implementing -b flag
sheida-shab eaf62b9
implementing ls -1
sheida-shab e85e714
implement ls -1 path
sheida-shab f0dde4b
Filtering hidden files name
sheida-shab de2cbfb
implementing -a flag
sheida-shab 99dfd5d
implementing basic wc
sheida-shab 604ccb5
implementing first wc statement
sheida-shab 303b96f
fixing presenting problems
sheida-shab 2a2f3df
implementing flags -l , -c , -w
sheida-shab 0597cbd
Update .gitignore and cat.js
sheida-shab aa561c7
Add support for -1 flag to control output format
sheida-shab 5b9cc2d
fixed wc repeated file read and duplicate code
sheida-shab 163f71f
Remove virtual environment and node_modules from repo
sheida-shab 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,2 @@ | ||
| node_modules | ||
| ../../implement-cowsay/.venv/ |
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,39 @@ | ||
| import { promises as fs } from "node:fs"; | ||
| import { glob } from "glob"; | ||
| async function readFile() { | ||
| let fileNamePattern; | ||
| let flag; | ||
| if (process.argv[2].startsWith("-")) { | ||
| flag = process.argv[2]; | ||
| fileNamePattern = process.argv[3]; | ||
| } else { | ||
| fileNamePattern = process.argv[2]; | ||
| } | ||
|
|
||
| const filesNameArray = await glob(fileNamePattern); | ||
| filesNameArray.sort(); | ||
| let lineNumber = 1; | ||
|
|
||
| for (const file of filesNameArray) { | ||
| const fileContent = await fs.readFile(file, "utf-8"); | ||
| if (flag == null) { | ||
| console.log(fileContent); | ||
| } else { | ||
| const linesOfText = fileContent.split(/\r?\n/); | ||
| if (linesOfText[linesOfText.length - 1].trim() === "") { | ||
| linesOfText.pop(); | ||
| } | ||
|
|
||
| for (const line of linesOfText) { | ||
| if (line.trim() === "" && flag === "-b") { | ||
| console.log(line); | ||
| } else { | ||
| console.log(`${lineNumber} ${line}`); | ||
| lineNumber++; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| readFile(); | ||
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,3 @@ | ||
| { | ||
| "type": "module" | ||
| } |
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,29 @@ | ||
| import { promises as fs } from "node:fs"; | ||
| async function listDir() { | ||
| let finalFileList; | ||
| const flag = process.argv[2]; | ||
| const argvArray = process.argv.slice(2); | ||
|
|
||
| const flags = argvArray.filter((item) => item.startsWith("-")); | ||
|
|
||
| const Path = | ||
| argvArray.filter((item) => !item.startsWith("-")) || process.cwd(); | ||
|
|
||
| const isSingleColumn = flags.includes("-1"); | ||
|
|
||
| const fileListArray = await fs.readdir(Path[0] || process.cwd()); | ||
| if (flags.includes("-a")) { | ||
| finalFileList = fileListArray; | ||
| } else { | ||
| finalFileList = fileListArray.filter((file) => !file.startsWith(".")); | ||
| } | ||
|
|
||
| if (isSingleColumn) { | ||
| for (const item of finalFileList) { | ||
| console.log(item); | ||
| } | ||
| } else { | ||
| console.log(finalFileList.join(" ")); | ||
| } | ||
| } | ||
| listDir(); |
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,3 @@ | ||
| { | ||
| "type": "module" | ||
| } |
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,3 @@ | ||
| { | ||
| "type": "module" | ||
| } |
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,66 @@ | ||
| import { promises as fs } from "node:fs"; | ||
| async function wcJsImplement() { | ||
|
|
||
| let totalLines=0,totalWords=0,TotalBytes=0; | ||
| let words,bytes; | ||
| const commandLineArray=process.argv.slice(2); | ||
| const flags = commandLineArray.filter((item) => item.startsWith("-")); | ||
|
|
||
| if(flags.length !==0 ) | ||
| { | ||
| commandLineArray.shift(); | ||
| } | ||
|
|
||
| function printOutput(lines,words,bytes,lable){ | ||
| switch (flags[0]) { | ||
| case "-l": | ||
| console.log(`${String(lines).padStart(4)} ${lable}`); | ||
| break; | ||
| case "-w": | ||
| console.log(`${String(words).padStart(4)} ${lable}`); | ||
| break; | ||
| case "-c": | ||
| console.log(`${String(bytes).padStart(4)} ${lable}`); | ||
| break; | ||
| default: | ||
| console.log( | ||
| `${String(lines).padStart(4)}${String(words).padStart( | ||
| 4 | ||
| )}${String(bytes).padStart(4)} ${lable}` | ||
| ); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| for(const file of commandLineArray){ | ||
| const buffer = await fs.readFile(file); | ||
| const fileContent=buffer.toString("utf-8"); | ||
| bytes=buffer.length; | ||
| TotalBytes += bytes; | ||
|
|
||
| const lines=fileContent.split(/\r?\n/); | ||
| let linesCount,wordsCount=0; | ||
| //Calculate count of lines | ||
| if(lines[lines.length-1].trim()===""){ | ||
| lines.pop(); | ||
| linesCount=lines.length; | ||
| totalLines += linesCount; | ||
| } | ||
| //calculate count of words | ||
| for(const line of lines){ | ||
| words=line.trim().split(/\s+/); | ||
| if (words[0].trim() !== ""){ | ||
| wordsCount += words.length; | ||
| } | ||
| } | ||
| totalWords += wordsCount; | ||
|
|
||
| printOutput(linesCount,wordsCount,bytes,file); | ||
| } | ||
|
|
||
| if(commandLineArray.length>1){ | ||
| printOutput(totalLines, totalWords, TotalBytes, "total"); | ||
| } | ||
|
|
||
| } | ||
| wcJsImplement(); |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I run this code I get an error
Cannot find package 'glob'. Do you see this also?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your comment but I don't see any error !