Skip to content

Added my own version of cat command #280

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
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Environnement virtuel
/venv/

# Fichiers de cache
__pycache__/
*.pyc

# Fichiers temporaires
*.tmp

# Fichiers d'environnement
.env

# Fichiers de logs
/logs/
264 changes: 210 additions & 54 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,62 +1,218 @@
<div id="top"></div>
# Building Your Own Cat-Tool
This challenge is to build your own version of the Unix Command line tool cat.

# Shared Solutions to Coding Challenges
I use for this challenge **argparse module** to parse my cat command line.

Publicly shared solutions to the [Coding Challenges](https://codingchallenges.fyi/).
## Table of Contents

- [Progress](#progress)
- [Get and Install my Cat Tool](#get-and-install-my-cat-tool)
- [Ready to use my cat-tool commands](#ready-to-use-my-cat-tool-commands)
- [Command to know the different possible commands of my cat-tool](#command-to-know-the-different-possible-commands-of-my-cat-tool)
- [Command to display content of one file](#command-to-display-content-of-one-file)
- [Command to display content of many files](#command-to-display-content-of-many-files)
- [Command to read input from standard in](#command-to-read-input-from-standard-in)
- [Command to number all the lines as they’re printed out](#command-to-number-all-the-lines-as-theyre-printed-out)
- [Command to number the lines as they’re printed out except the blank-lines](#command-to-number-the-lines-as-theyre-printed-out-except-the-blank-lines)

## Progress
0. Test files received to test solution with.
1. Open specific file on the command line and write its contents to standard out.
2. Reads input from standard in
3. Can concatenate files
4. Number the lines as they’re printed out
5. Number lines but exclude blank lines from being numbered in output

## Get and Install my Cat Tool
### 1. Clone the Repo :
```
gh repo clone oussy96/coding-challenges
```
### 2. Move to the Cat-Tool Project :
```
cd coding-challenges/cat-tool
```
### 3. Create a Vitual Environment (Recommended) :
```
python -m venv venv
```

### 4. Activate the Virtual Environment:
```
source venv/bin/activate
```

## Ready to use my cat-tool commands
### Command to know the different possible commands of my cat-tool
```
% python cccat.py --help
```
Output :
```
usage: cccat [-h] [-] [-n] [-b] [filename ...]

Process cat file.

positional arguments:
filename The name of file to display his content

options:
-h, --help show this help message and exit
-, --read Read the input from standard in
-n, --number Number the lines printed out including non-blank lines
-b, --bnumber Number the lines printed out excluding non-blank lines
```

Join the [Discord Community](https://discord.gg/zv4RKDcEKV).
### Command to display content of one file
```
python cccat.py test.txt
```
Output :
```
"Your heart is the size of an ocean. Go find yourself in its hidden depths."
"The Bay of Bengal is hit frequently by cyclones. The months of November and May, in particular, are dangerous in this regard."
"Thinking is the capital, Enterprise is the way, Hard Work is the solution."
"If You Can'T Make It Good, At Least Make It Look Good."
"Heart be brave. If you cannot be brave, just go. Love's glory is not a small thing."
"It is bad for a young man to sin; but it is worse for an old man to sin."
"If You Are Out To Describe The Truth, Leave Elegance To The Tailor."
"O man you are busy working for the world, and the world is busy trying to turn you out."
"While children are struggling to be unique, the world around them is trying all means to make them look like everybody else."
"These Capitalists Generally Act Harmoniously And In Concert, To Fleece The People."
```

### How To Add Your Solution
To add your solution follow the process for [making a pull request to an open-source project](https://github.com/gabrieldemarmiesse/getting_started_open_source).
### Command to display content of many files
```
python cccat.py test.txt test2.txt
```
Output :
```
"Your heart is the size of an ocean. Go find yourself in its hidden depths."
"The Bay of Bengal is hit frequently by cyclones. The months of November and May, in particular, are dangerous in this regard."
"Thinking is the capital, Enterprise is the way, Hard Work is the solution."
"If You Can'T Make It Good, At Least Make It Look Good."
"Heart be brave. If you cannot be brave, just go. Love's glory is not a small thing."
"It is bad for a young man to sin; but it is worse for an old man to sin."
"If You Are Out To Describe The Truth, Leave Elegance To The Tailor."
"O man you are busy working for the world, and the world is busy trying to turn you out."
"While children are struggling to be unique, the world around them is trying all means to make them look like everybody else."
"These Capitalists Generally Act Harmoniously And In Concert, To Fleece The People."
"I Don'T Believe In Failure. It Is Not Failure If You Enjoyed The Process."
"Do not get elated at any victory, for all such victory is subject to the will of God."
"Wear gratitude like a cloak and it will feed every corner of your life."
"If you even dream of beating me you'd better wake up and apologize."
"I Will Praise Any Man That Will Praise Me."
"One Of The Greatest Diseases Is To Be Nobody To Anybody."
"I'm so fast that last night I turned off the light switch in my hotel room and was in bed before the room was dark."
"People Must Learn To Hate And If They Can Learn To Hate, They Can Be Taught To Love."
"Everyone has been made for some particular work, and the desire for that work has been put in every heart."
"The less of the World, the freer you live."
```

Essentially:
1. Fork this repo and clone it.
2. Create a branch and make your change.
3. Push your branch to your fork.
4. Open a PR against this repo.
### Command to read input from standard in
```
head -n2 test2.txt | python cccat.py -
```
OR
```
head -n2 test2.txt | python cccat.py
```
Output :
```
"I Don'T Believe In Failure. It Is Not Failure If You Enjoyed The Process."
"Do not get elated at any victory, for all such victory is subject to the will of God."
```

### Command to number all the lines as they’re printed out
```
% head -n3 test.txt | python cccat.py -n
```
Output :
```
1 "Your heart is the size of an ocean. Go find yourself in its hidden depths."
2 "The Bay of Bengal is hit frequently by cyclones. The months of November and May, in particular, are dangerous in this regard."
3 "Thinking is the capital, Enterprise is the way, Hard Work is the solution."
```
Also the blank-lines :
```
sed G test.txt | python cccat.py -n | head -n4
```
Output :
```
1 "Your heart is the size of an ocean. Go find yourself in its hidden depths."
2
3 "The Bay of Bengal is hit frequently by cyclones. The months of November and May, in particular, are dangerous in this regard."
4
```

### Command to number the lines as they’re printed out except the blank-lines
```
sed G test.txt | python cccat.py -b | head -n5
```
Output :
```
1 "Your heart is the size of an ocean. Go find yourself in its hidden depths."

2 "The Bay of Bengal is hit frequently by cyclones. The months of November and May, in particular, are dangerous in this regard."

3 "Thinking is the capital, Enterprise is the way, Hard Work is the solution."
```

## Test our project using the TestCccat unittest class

The `TestCccat` class contains unit tests for the `cccat` module, which is responsible for processing and displaying content from files or standard input.

## Table of Contents

- [Build your own wc Tool](Solutions/challenge-wc.md)
- [Build your own JSON Parser](Solutions/challenge-json-parser.md)
- [Build your own Compression Tool](Solutions/challenge-huffman.md)
- [Build your own cut Tool](Solutions/challenge-cut.md)
- [Build your own Load Balancer](Solutions/challenge-load-balancer.md)
- [Build your own Sort Tool](Solutions/challenge-sort.md)
- [Build your own Calculator](Solutions/challenge-calculator.md)
- [Build your own Redis Server](Solutions/challenge-redis.md)
- [Build your own grep](Solutions/challenge-grep.md)
- [Build your own uniq](Solutions/challenge-uniq.md)
- [Build your own Web Server](Solutions/challenge-webserver.md)
- [Build your own URL Shortener](Solutions/challenge-url-shortener.md)
- [Build your own diff](Solutions/challenge-diff.md)
- [Build your own Shell](Solutions/challenge-shell.md)
- [Build your own cat Tool](Solutions/challenge-cat.md)
- [Build your own IRC Client](Solutions/challenge-irc.md)
- [Build your own Memcached Server](Solutions/challenge-memcached.md)
- [Build your own Spotify Client](Solutions/challenge-spotify.md)
- [Build your own Discord Bot](Solutions/challenge-discord.md)
- [Build your own LinkedIn Carousel Generator](Solutions/challenge-licg.md)
- [Build your own sed](Solutions/challenge-sed.md)
- [Build your own DNS Resolver](Solutions/challenge-dns-resolver.md)
- [Build your own Traceroute](Solutions/challenge-traceroute.md)
- [Build your own Realtime Chat Client and Server](Solutions/challenge-realtime-chat.md)
- [Build your own NATS Message Broker](Solutions/challenge-nats.md)
- [Build your own Git Client](Solutions/challenge-git.md)
- [Build your own Rate Limiter](Solutions/challenge-rate-limiter.md)
- [Build your own Scheduling Automation App](Solutions/challenge-scheduleing-automation.md)
- [Build your own Lisp Interpreter](Solutions/challenge-lisp.md)
- [Build your own Tetris](Solutions/challenge-tetris.md)

- [Build your own QR Code Generator](Solutions/challenge-qr-generator.md)
- [Build your own CronTab Tool](Solutions/challenge-crontab.md)
- [Build your own head](Solutions/challenge-head.md)
- [Build your own jq](Solutions/challenge-jq.md)
- [Build your own Pong](Solutions/challenge-pong.md)
- [Build your own curl](Solutions/challenge-curl.md)
- [Build your own HTTP(S) Load Tester](Solutions/challenge-load-tester.md)
- [Build Your Own Data Privacy Vault](Solutions/challenge-data-privacy-vault.md)
- [Build Your Own Password Cracker](Solutions/challenge-password-cracker.md)
- [Build Your own Spell Checker using Bloom Filter](Solutions/challenge-bloom-filter-spell-checker.md)

<p align="right">(<a href="#top">🔼 Back to top</a>)</p>
- [Introduction](#introduction)
- [Setup](#setup)
- [Tests](#tests)
- [parse_arguments Function](#parse_arguments-function)
- [read_file_content Function](#read_file_content-function)
- [cc_cat Function](#cc_cat-function)
- [read_input Function](#read_input-function)
- [read_input_numbered_lines Function](#read_input_numbered_lines-function)
- [read_input_bnumbered_lines Function](#read_input_bnumbered_lines-function)
- [Conclusion](#conclusion)

### Introduction

This test suite verifies the functionality of various functions within the `cccat` module. It utilizes Python's `unittest` framework to define test cases covering different scenarios and edge cases.

### Setup

To run the tests, ensure that you have Python installed on your system. The tests can be executed using the following command:

```bash
python -m unittest -v tests/test_cccat.py
```

### Tests

#### parse_arguments Function

- Tests the `parse_arguments` function with different command-line arguments to ensure correct parsing and handling of options.

#### read_file_content Function

- Tests the `read_file_content` function to verify that it correctly reads and returns the content of a file.

#### cc_cat Function

- Tests the `cc_cat` function with various scenarios, including reading content from multiple files, standard input, and applying line numbering options.

#### read_input Function

- Tests the `read_input` function to ensure that it correctly reads and returns input from standard input.

#### read_input_numbered_lines Function

- Tests the `read_input_numbered_lines` function to verify that it correctly numbers lines from standard input.

#### read_input_bnumbered_lines Function

- Tests the `read_input_bnumbered_lines` function to ensure that it correctly numbers lines from standard input, excluding blank lines.

### Conclusion

The `TestCccat` test class provides comprehensive coverage of the `cccat` module's functionality, ensuring its reliability and correctness across various scenarios.
Loading