extern crate clap; use clap::{App, Arg}; #[derive(Debug)] pub struct Config { pub pattern: String, pub ignore_case: bool, pub path: String, pub use_gitignore: bool, pub omit_filenames: bool, pub match_only: bool, } impl Config { pub fn from_args() -> Config { let matches = App::new("Rack") .version("0.1") .about("Like Ack but in Rust") .arg( Arg::with_name("ignore case") .short("i") .help("Ignore case when looking for matches"), ) .arg( Arg::with_name("pattern") .help("The pattern you're looking for") .index(1) .required(true), ) .arg( Arg::with_name("path") .help("Path to search in") .index(2) .default_value(""), ) .arg( Arg::with_name("gitignore") .long("no-gitignore") .help("Include results that are specified in .gitignore"), ) .arg( Arg::with_name("omit filenames") .short("h") .help("Omit file names in results"), ) .arg( Arg::with_name("only match") .short("o") .help("Only print matched text") ) .get_matches(); Config { pattern: String::from(matches.value_of("pattern").unwrap()), ignore_case: matches.is_present("ignore case"), path: String::from(matches.value_of("path").unwrap()), use_gitignore: !matches.is_present("gitignore"), omit_filenames: matches.is_present("omit filenames"), match_only: matches.is_present("only match"), } } }