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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
use std::fmt::Display; use std::time::Duration; #[derive(Debug, Copy, Clone)] pub struct Config { prompt_missing_env_vars: bool, verbosity: u8, quiet: bool, print_file_paths: bool, timeout: Option<Duration>, curl: bool, } impl Default for Config { fn default() -> Self { Config { prompt_missing_env_vars: false, verbosity: 1, quiet: false, print_file_paths: false, timeout: None, curl: false, } } } impl Config { pub const fn new( prompt_missing_env_vars: bool, verbosity: u8, quiet: bool, print_file_paths: bool, timeout: Option<Duration>, curl: bool, ) -> Self { Config { prompt_missing_env_vars, verbosity, quiet, print_file_paths, timeout, curl, } } pub fn prompt_missing_env_vars(&self) -> bool { self.prompt_missing_env_vars } pub fn verbosity(&self) -> u8 { match self.quiet { true => 0, false => self.verbosity } } pub fn print_file_paths(&self) -> bool { self.print_file_paths } pub fn timeout(&self) -> Option<Duration> { self.timeout } pub fn curl(&self) -> bool { self.curl } pub fn log<S: Display>( &self, level: u8, message: S ) { if self.verbosity() >= level { eprint!("{}", message); } } pub fn logln<S: Display>( &self, level: u8, message: S ) { if self.verbosity() >= level { eprintln!("{}", message); } } }