generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 42
Glasgow | 25-SDC-Nov | Nataliia Volkova | Sprint 3 | Implement_shell_tools_in_JS_with_NODE #237
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
Nataliia74
wants to merge
3
commits into
CodeYourFuture:main
Choose a base branch
from
Nataliia74:implement_shell_tools_exercises
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
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 |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import process from "node:process"; | ||
| import { promises as fs } from "node:fs"; | ||
|
|
||
| const arrArgv = process.argv.slice(2); | ||
|
|
||
| const numberLines = arrArgv.includes("-n"); | ||
| const numberNonemptyLines = arrArgv.includes("-b"); | ||
|
|
||
| const nonFlagArrArgv = arrArgv.filter((arr) => !arr.startsWith("-")); | ||
|
|
||
| let number = 1; | ||
|
|
||
| for (let file of nonFlagArrArgv) { | ||
| const content = await fs.readFile(file, "utf-8"); | ||
|
|
||
| const linedText = content.split("\n"); | ||
|
|
||
| const formatLines = (line) => { | ||
| return `${String(number++).padStart(3)} ${line}`; | ||
| }; | ||
|
|
||
| const numbered = linedText.map((line) => { | ||
| if (numberNonemptyLines && line.trim() === "") { | ||
| return line; | ||
| } | ||
| if (numberNonemptyLines || numberLines) { | ||
| return formatLines(line); | ||
| } | ||
| return line; | ||
| }); | ||
| console.log(numbered.join("\n")); | ||
| } |
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,50 @@ | ||
| import process from "node:process"; | ||
| import { promises as fs } from "node:fs"; | ||
| import path from "node:path"; | ||
|
|
||
| const arrArgv = process.argv.slice(2); | ||
|
|
||
| const longFormat = arrArgv.includes("-l"); | ||
| const showHidden = arrArgv.includes("-a"); | ||
|
|
||
| let paths = arrArgv.filter((argv) => !argv.startsWith("-")); | ||
| if (paths.length === 0) paths = ["."]; | ||
|
|
||
| const printWholeList = (stats, name) => { | ||
| const permissions = (stats.mode & 0o777).toString(8); | ||
| const sizeFile = stats.size; | ||
| const owner = stats.uid; | ||
| const group = stats.gid; | ||
| const timeMod = stats.mtime.toLocaleString(); | ||
|
|
||
| console.log( | ||
| `${permissions}, ${owner}, ${group}, ${sizeFile}, ${timeMod}, ${name}` | ||
| ); | ||
| }; | ||
| for (const listFile of paths) { | ||
| const status = await fs.stat(listFile); | ||
| if (status.isFile()) { | ||
| if (longFormat) { | ||
| printWholeList(status, listFile); | ||
| } else { | ||
| console.log(listFile); | ||
| } | ||
| } else { | ||
| let files = await fs.readdir(listFile, { withFileTypes: true }); | ||
|
|
||
| if (!showHidden) { | ||
| files = files.filter((file) => !file.name.startsWith(".")); | ||
| } | ||
|
|
||
| for (const file of files) { | ||
| const wholePath = path.join(listFile, file.name); | ||
Nataliia74 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if (longFormat) { | ||
| const statusFile = await fs.stat(wholePath); | ||
| printWholeList(statusFile, file.name); | ||
| } else { | ||
| console.log(file.name); | ||
| } | ||
| } | ||
| } | ||
| } | ||
Nataliia74 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,38 @@ | ||
| import process from "node:process"; | ||
| import { promises as fs } from "node:fs"; | ||
|
|
||
| const arrArgv = process.argv.slice(2); | ||
|
|
||
| const lines = arrArgv.includes("-l"); | ||
| const words = arrArgv.includes("-w"); | ||
| const bytes = arrArgv.includes("-c"); | ||
|
|
||
| const noFlags = !lines && !words && !bytes; | ||
|
|
||
| const paths = arrArgv.filter((argv) => !argv.startsWith("-")); | ||
|
|
||
| for (let path of paths) { | ||
| const context = await fs.readFile(path, "utf-8"); | ||
|
|
||
| const countLines = context.split(/\r?\n/).length; | ||
| const countWords = context.split(/\s+/).length; | ||
| const countBytes = Buffer.byteLength(context, "utf-8"); | ||
|
|
||
| let startInput = ""; | ||
|
|
||
| if (noFlags || lines) { | ||
| startInput += `${countLines} `; | ||
| } | ||
|
|
||
| if (noFlags || words) { | ||
| startInput += `${countWords} `; | ||
| } | ||
|
|
||
| if (noFlags || bytes) { | ||
| startInput += `${countBytes} `; | ||
| } | ||
|
|
||
| startInput += path; | ||
|
|
||
| console.log(startInput); | ||
| } |
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.