This repository, minigrep, is a simple command-line tool implemented in Rust that mimics basic functionality of the grep command. It allows you to search for a specified query within a text file, with options for case-sensitive and case-insensitive searches.
- File Reading: Reads contents from a specified file, provided through the command line.
- Case Sensitivity Control: Case-sensitive by default; environment variable
CASE_INSENSITIVE=1enables case-insensitive search. - Configurable Queries: Accepts a search query and filename as command-line arguments.
- Error Handling: Handles missing or invalid arguments and file read errors gracefully using the
Resulttype and Rust’s?operator.
runFunction: Core function that executes the search logic and displays matching lines.ConfigStruct: Manages command-line arguments, including filename, query, and case sensitivity, with input validation.- Search Functions:
searchfor case-sensitive search.search_case_insensitivefor case-insensitive search by converting both query and contents to lowercase.
Includes tests for both search modes, ensuring accurate results across case variations. This tool demonstrates core Rust principles like error handling, ownership, and test-driven development (TDD).