1use std::{fmt::Display, time::Duration};
2
3#[derive(Debug, Clone, Copy, Default)]
4pub struct Config {
5 no_prompt: bool,
6 verbose: u8,
7 quiet: bool,
8 print_paths: bool,
9 timeout_ms: Option<u64>,
10 curl: bool,
11}
12
13impl Config {
14 pub fn new(
15 no_prompt: bool,
16 verbose: u8,
17 quiet: bool,
18 print_paths: bool,
19 timeout_ms: Option<u64>,
20 curl: bool,
21 ) -> Self {
22 Config {
23 no_prompt,
24 verbose,
25 quiet,
26 print_paths,
27 timeout_ms,
28 curl,
29 }
30 }
31
32 pub fn prompt_missing_env_vars(&self) -> bool {
33 !self.no_prompt
34 }
35
36 pub fn verbosity(&self) -> u8 {
37 match self.quiet {
38 true => 0,
39 false => self.verbose + 1,
40 }
41 }
42
43 pub fn print_file_paths(&self) -> bool {
44 self.print_paths
45 }
46
47 pub fn timeout(&self) -> Option<Duration> {
48 self.timeout_ms.map(Duration::from_millis)
49 }
50
51 pub fn curl(&self) -> bool {
52 self.curl
53 }
54
55 pub fn log<S: Display>(&self, level: u8, message: S) {
56 if self.verbosity() >= level {
57 eprint!("{}", message);
58 }
59 }
60
61 pub fn logln<S: Display>(&self, level: u8, message: S) {
62 if self.verbosity() >= level {
63 eprintln!("{}", message);
64 }
65 }
66}