keyword_in_file 0.1.0

A program used to find a file then search for a key word in said file
Documentation
//! # WEBSITE READING
//! 
//! This code peice is used to put agruements into your terminal when running cargo, to   1: Search for the file name (txt) ,   2: Search for a specific word in the file.txt
//! 
//! HOW IT'S USED:     Cargo run file_name  Word_to_seach_for  
//! To turn off search caps sensitive you can run:    $env:CAPS_SENS = "true/false"    
//! 
/// # Examples
/// 
/// ```rust
/// 
/// //WITHOUT ANY ARGUEMENTS
/// pub fn reading_file() {
///     use std::fs::File;
///     let mut message = String::new();
///     let file = File::open("Name.txt");
/// 
///     match file {
///         Ok(mut file) => {
///             use std::io::Read;
///             let file_text = file.read_to_string(&mut message);
/// 
///             match file_text {
///                 Ok(_) => println!("FILE TEXT: {}", message),
///                 Err(error) => println!("HAD THE ERROR WHILE READING {}", error),
///             }
///         },
///         Err(error) => println!("THE ERROR FOUND IS: {:?}", error),
///     }
/// }
/// pub fn main() {
///     reading_file();
/// }
/// ```

pub fn reading_file() {

    //getting the arguements for the file and the search

    use std::env;

    let caps_toggle= env::var("CAPS_SENS").unwrap_or_default() == "true";

    let args: Vec<String> = env::args().collect();

    if args.len() < 2 {

        use std::process;

        println!("DIDNT USE AGRUEMENTS, PLEASE RUN CARGO WITH ARGUEMENTS e.g cargo run file.txt search_word");

        process::exit(1);

    }

    let file = &args[1];
    let search = &args[2];



    //code to read and search for the file

    use std::fs::File;
    use std::io::Read;


    let file = File::open(file);

    match file {

        Ok(mut file) => {

            let mut message = String::new();

            let reading = file.read_to_string(&mut message);

            match reading {
                Ok(_) => {

                    if caps_toggle {

                        println!("CAPS_SENS");

                        for line in message.lines() {
                           
                            if line.to_string().to_lowercase().contains(&search.to_lowercase()) {
                                println!("{}", line);
                            } else {
                                println!("couldnt find {}", search);
                            }
                        }

                    } else  {

                        println!("NONE CAPS_SENS");

                        for line in message.lines() {

                            if line.to_string().contains(search) {
                                println!("{}", line);
                            } 
                        }
                
                    }
                

                },

                Err(error) => println!("ERROR WHILE READING {:?}", error)
            }

        },

        Err(error) => println!("{:?}", error)
    }
}

pub fn main() {

    reading_file();

}