A command-line tool written in Rust that searches for specific patterns within text files. The application provides detailed logging and error handling capabilities.
- Search for text patterns in files
- Detailed error messages
- Configurable logging verbosity
- Command-line argument parsing with help documentation
-
Make sure you have Rust and Cargo installed. If not, install them from rustup.rs
-
Clone the repository:
git clone [your-repository-url]
cd pattern-search-cli
- Build the project:
cargo build --release
The compiled binary will be available in target/release/
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
<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
- Create a test file:
echo "Hello World\nTest Line\nHello Rust" > test.txt
- 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
- 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
clap
: Command line argument parsinganyhow
: Error handlinglog
andenv_logger
: Logging functionalitystd
: Rust standard library components
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
To contribute to the project:
- Fork the repository
- Create a feature branch
- Run tests:
cargo test
- Submit a pull request