forked from CodeYourFuture/Module-Tools
-
Notifications
You must be signed in to change notification settings - Fork 0
BARCELONA | OCT-25-01 | FAITH MICHEAL | SPRINT 4 | IMPLEMENT COWSAY #7
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
SlimMicheals
wants to merge
10
commits into
main
Choose a base branch
from
implement-cowsay
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
10 commits
Select commit
Hold shift + click to select a range
d936ded
Implement basic cat command
SlimMicheals c1d3370
Add -n flag to cat for line numbering
SlimMicheals 3aa62e0
Add -b flag to cat for numbering non-empty lines
SlimMicheals 690621b
Implement basic ls -1 functionality
SlimMicheals 72f8744
Add directory argument support to ls
SlimMicheals 51a2abd
Add -a flag to show hidden files in ls
SlimMicheals aeca96e
implement wc for single file (lines, words, characters)
SlimMicheals e8b9d2a
Add multiple file support to wc
SlimMicheals e28760f
Add wc flags -l, -w, -c
SlimMicheals 7ec1b65
Implement cowsay CLI using argparse and cowsay library
SlimMicheals 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,26 @@ | ||
| import argparse | ||
| import cowsay | ||
|
|
||
|
|
||
| def main(): | ||
| parser = argparse.ArgumentParser(description="Make animals say things") | ||
| parser.add_argument( | ||
| "--animal", | ||
| choices=cowsay.char_names, | ||
| default="cow", | ||
| help="The animal to be saying things." | ||
| ) | ||
| parser.add_argument( | ||
| "message", | ||
| nargs="+", | ||
| help="The message to say." | ||
| ) | ||
|
|
||
| args = parser.parse_args() | ||
| message = " ".join(args.message) | ||
|
|
||
| print(cowsay.get_output_string(args.animal, message)) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
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,34 @@ | ||
| const fs = require("fs"); | ||
|
|
||
| const args = process.argv.slice(2); | ||
|
|
||
| const showLineNumbers = args.includes("-n"); | ||
| const numberNonEmptyLines = args.includes("-b"); | ||
|
|
||
| const files = args.filter(arg => arg !== "-n" && arg !== "-b"); | ||
|
|
||
| for (const file of files) { | ||
| const content = fs.readFileSync(file, "utf8"); | ||
|
|
||
| if (numberNonEmptyLines) { | ||
| const lines = content.split("\n"); | ||
| let lineNumber = 1; | ||
|
|
||
| lines.forEach((line) => { | ||
| if (line.trim() !== "") { | ||
| console.log(`${lineNumber} ${line}`); | ||
| lineNumber++; | ||
| } else { | ||
| console.log(line); | ||
| } | ||
| }); | ||
| } else if (showLineNumbers) { | ||
| const lines = content.split("\n"); | ||
|
|
||
| lines.forEach((line, index) => { | ||
| console.log(`${index + 1} ${line}`); | ||
| }); | ||
| } else { | ||
| process.stdout.write(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,21 @@ | ||
| const fs = require("fs"); | ||
|
|
||
| const args = process.argv.slice(2); | ||
|
|
||
| const showAll = args.includes("-a"); | ||
|
|
||
| // remove -a from arguments | ||
| const filteredArgs = args.filter(arg => arg !== "-a"); | ||
|
|
||
| const target = filteredArgs[0] || "."; | ||
|
|
||
| let files = fs.readdirSync(target); | ||
|
|
||
| // hide hidden files if -a is NOT used | ||
| if (!showAll) { | ||
| files = files.filter(file => !file.startsWith(".")); | ||
| } | ||
|
|
||
| files.forEach(file => { | ||
| console.log(file); | ||
| }); |
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 @@ | ||
| const fs = require("fs"); | ||
|
|
||
| const args = process.argv.slice(2); | ||
|
|
||
| const showLines = args.includes("-l"); | ||
| const showWords = args.includes("-w"); | ||
| const showChars = args.includes("-c"); | ||
|
|
||
| const files = args.filter( | ||
| (arg) => arg !== "-l" && arg !== "-w" && arg !== "-c" | ||
| ); | ||
|
|
||
| for (const file of files) { | ||
| const content = fs.readFileSync(file, "utf8"); | ||
|
|
||
| const lines = content.split("\n").length; | ||
| const words = content.trim().split(/\s+/).length; | ||
| const chars = content.length; | ||
|
|
||
| if (showLines) { | ||
| console.log(lines, file); | ||
| } else if (showWords) { | ||
| console.log(words, file); | ||
| } else if (showChars) { | ||
| console.log(chars, file); | ||
| } else { | ||
| console.log(lines, words, chars, file); | ||
| } | ||
| } | ||
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.
maybe here if the first condition is True the if loop breaks