Skip to content

syamimhazmi/rust-cli-grrs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pattern Search CLI

A command-line tool written in Rust that searches for specific patterns within text files. The application provides detailed logging and error handling capabilities.

Features

  • Search for text patterns in files
  • Detailed error messages
  • Configurable logging verbosity
  • Command-line argument parsing with help documentation

Installation

  1. Make sure you have Rust and Cargo installed. If not, install them from rustup.rs

  2. Clone the repository:

git clone [your-repository-url]
cd pattern-search-cli
  1. Build the project:
cargo build --release

The compiled binary will be available in target/release/

Usage

Basic usage:

./target/release/pattern-search-cli <PATTERN> <FILE_PATH>

With verbose logging:

./target/release/pattern-search-cli <PATTERN> <FILE_PATH> -v

Example:

./target/release/pattern-search-cli "Hello" sample.txt
./target/release/pattern-search-cli "Error" logs/app.log -vvv

Command Line Arguments

  • <PATTERN>: The text pattern to search for in the file
  • <FILE_PATH>: Path to the file to search in
  • -v, --verbose: Enable verbose output (can be used multiple times for increased verbosity)
  • -h, --help: Display help information
  • -V, --version: Display version information

Testing

  1. Create a test file:
echo "Hello World\nTest Line\nHello Rust" > test.txt
  1. Run basic tests:
# Should find two lines containing "Hello"
./target/release/pattern-search-cli "Hello" test.txt

# Should find one line containing "Test"
./target/release/pattern-search-cli "Test" test.txt

# Test with verbose logging
./target/release/pattern-search-cli "Hello" test.txt -v
  1. Test error handling:
# Test with non-existent file
./target/release/pattern-search-cli "pattern" nonexistent.txt

# Test with unreadable file (create file without read permissions)
touch unreadable.txt
chmod 000 unreadable.txt
./target/release/pattern-search-cli "pattern" unreadable.txt

Dependencies

  • clap: Command line argument parsing
  • anyhow: Error handling
  • log and env_logger: Logging functionality
  • std: Rust standard library components

Error Handling

The application handles several error cases:

  • File not found
  • Permission denied
  • Invalid file content
  • File reading errors

Error messages include:

  • Detailed context about the failure
  • File path information
  • Underlying system error details

Development

To contribute to the project:

  1. Fork the repository
  2. Create a feature branch
  3. Run tests: cargo test
  4. Submit a pull request

About

🦀 Pattern Search CLI

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages