CLIApps 0.2.5

A tool to search files
use clap::Parser;
use std::fs;
use std::env;
use anyhow::{Context, Result};

//Struct for creating the CLI object with the inputted arguments
#[derive(Parser)]
struct Cli {
	comm: String,
	patt: String,
	path: std::path::PathBuf,
}


fn main() -> Result<()> {
	//Store arguments in a string vector temporarily
	let args_check: Vec<String> = env::args().collect();
	
	//If statements for checking the command that was passed
	if args_check[1].to_string().to_lowercase() == "greppy" {
		let args = Cli::parse();
		let content = std::fs::read_to_string(&args.path)
			.with_context(|| format!("could not read file '{}'", args.path.display()))?;
		 //For loop which will loop through the lines of the file, and check for whatever is being searched, printing it if it's found
		 for line in content.lines() {
			 if line.contains(&args.patt) {
			 println!("{}", line);
			 }
		 }
	}
	
	else if args_check[1].to_string().to_lowercase() == "listy" {
		let paths = fs::read_dir("./").unwrap();
		//For loop that simply prints the current files in the directory
		for path in paths {
			println!("{}", path.unwrap().path().display())
		}
	}
		
	else if args_check[1].to_string().to_lowercase() == "catty" {
		let args = Cli{ comm: args_check[1].to_string().to_lowercase(), patt: args_check[2].to_string(), path: "".into()};
		let content = std::fs::read_to_string(&args.patt)
			.with_context(|| format!("could not read file '{}'", args.path.display()))?;
		//For loop for printing each line of the file being passed
		for line in content.lines() {
			println!("{}", line);
		}
		
	}
	
	else if args_check[1].to_string().to_lowercase() == "echoey" {
		//Simple print statement for echoing the string passed through the echo clone
		println!("{}", args_check[2]);
	}
	 Ok(())
}