Skip to content

Jolah1/minigrep

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

minigrep — A Simple CLI Text Search Tool in Rust

minigrep is a beginner-friendly command-line tool written in Rust, inspired by the Unix grep utility. It allows you to search for lines containing a query string within a text file. This project shows file I/O, error handling, and ownership in Rust.

Features

  • Search for exact matches of a query string in a file.
  • Case-insensitive search option using an environment variable.
  • Graceful error handling with user-friendly messages.
  • Demonstrates idiomatic Rust patterns such as Result, Option, struct, and module organization.

Built With

🚀 Getting Started

Prerequisites

  • Ensure Rust and Cargo are installed
    You can install Rust using rustup:

    curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
    

    Clone the repository

    git clone https://github.com/jolah1/minigrep.git
    cd minigrep

    Build the Project

    cargo build --release

    Run the project

    cargo run -- body poem.txt

    Enable Case-Insensitive Search

    Set the CASE_INSENSITIVE environment variable before running:

    ``bash CASE_INSENSITIVE=1 cargo run -- "to" poem.txt

    Or on Windows (PowerShell):
    ```bash
    $env:CASE_INSENSITIVE=1
    cargo run -- "to" poem.txt
    

    Running Tests

    cargo test

    Concepts Demonstrated

    Ownership and borrowing

  • String slices and lifetimes

  • Structs and enums

  • File reading with std::fs

  • Pattern matching with match

  • Error propagation using Result

  • Unit testing with #[test]

Contributions

Contributions are welcome! Please fork the repository and open a pull request. Thank you!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages