Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/victoriacheng15/cc-cat-rs
Built a cat command tool in Rust - learning on paws!
https://github.com/victoriacheng15/cc-cat-rs
rust rust-lang unix
Last synced: 26 days ago
JSON representation
Built a cat command tool in Rust - learning on paws!
- Host: GitHub
- URL: https://github.com/victoriacheng15/cc-cat-rs
- Owner: victoriacheng15
- License: mit
- Created: 2024-02-08T23:53:53.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2024-02-14T15:19:37.000Z (9 months ago)
- Last Synced: 2024-10-03T23:40:14.229Z (about 1 month ago)
- Topics: rust, rust-lang, unix
- Language: Rust
- Homepage:
- Size: 23.4 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Coding Challenges - Write Your own cat tool
This is a Rust version of the UNIX cat tool. Like the original cat tool, it allows you to:
- Display line number on each line with `-n`
- Display line number on nonempty line with `-b`
- Display the help with `--help`## Getting Started
1. Installation
```bash
git clone [email protected]:victoriacheng15/cc-cat-rs.gitcd cc-cat-rs
```2. Have Rust on your computer?
If you have not installed Rust on your computer, please refer to this [Install Rust Guide](https://www.rust-lang.org/tools/install).
3. Once you have Rust installed!
First, run with the cat tool
```bash
cat test.txt
```
Secondly, run with the Rust version of cat tool
```bash
cargo run -- test.txt
```
Lasty, compare the outputs from both in the terminal!## Usage
| Flag | Description |
| :----: | :----------------------------------- |
| -n | display line number on each line |
| -b | display line number on nonempty line |
| --help | display help |Examples:
```bash
cargo run -- test.txt test2.txthead -n3 test.txt | cargo run -- -
head -n3 test.txt | cargo run -- -n
sed G test.txt | cargo run -- -b
sed G test.txt | cargo run -- -b | head -n5
```## What did I learn from this?
Initially, I encountered a setback where the code wouldn't process a single file only (e.g., `cargo run -- test.txt`).
After debugging with logging, I zeroed in on the culprit: the `args` length. I had been checking for a minimum of two arguments. This was the reason why the program wouldn’t process a single file.
What was the fix? To effectively read contents from files, we need the files themselves. Thereforce, I ensured the `args` array exclusively contains file paths. This way, I can directly determine the number of files provided. If files exist, the program retrieves their contents; otherwise, it reads from standard input.
Key Takeaways:
- Take breaks to refresh your perspective. Stepping away can help you see things differently and identify solutions.
- Utilize a process of elimination to isolate the root cause. Systematically rule out possibilities until you pinpoint the issue.## Links
- [Write Your Own cat Tool](https://codingchallenges.fyi/challenges/challenge-cat)
- [Coding Challenges Website](https://codingchallenges.fyi)