1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
use clap::ArgMatches; pub struct Config { pub context: usize, pub max_pages: usize, pub quiet: bool, } impl Default for Config { fn default() -> Self { Self { context: 3, max_pages: 100, quiet: false, } } } impl Config { pub fn new() -> Self { Self::default() } pub fn modify_with_argmatches(&mut self, matches: &ArgMatches) { if let Some(context_str) = matches.value_of("context") { if let Ok(context) = context_str.parse() { self.context = context; } } if let Some(max_pages_str) = matches.value_of("max-pages") { if let Ok(max_pages) = max_pages_str.parse() { self.max_pages = max_pages; } } self.quiet = matches.is_present("quiet"); } }