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
use serde::{Deserialize, Serialize};

/// Options for controlling the behavior of browserslist.
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Opts {
    #[serde(default)]
    pub(crate) mobile_to_desktop: bool,

    #[serde(default)]
    pub(crate) ignore_unknown_versions: bool,

    #[serde(default)]
    pub(crate) config: Option<String>,

    #[serde(default)]
    pub(crate) env: Option<String>,

    #[serde(default)]
    pub(crate) path: Option<String>,

    #[serde(default)]
    pub(crate) throw_on_missing: bool,
}

impl Opts {
    /// Create new options with default values.
    pub fn new() -> Self {
        Self::default()
    }

    /// Use desktop browsers if Can I Use doesn’t have data about this mobile version.
    pub fn mobile_to_desktop(&mut self, flag: bool) -> &mut Self {
        self.mobile_to_desktop = flag;
        self
    }

    /// If `true`, ignore unknown versions then return empty result;
    /// otherwise, reject with an error.
    pub fn ignore_unknown_versions(&mut self, flag: bool) -> &mut Self {
        self.ignore_unknown_versions = flag;
        self
    }

    /// Path to configuration file with queries.
    pub fn config<S: AsRef<str>>(&mut self, config_path: S) -> &mut Self {
        self.config = Some(config_path.as_ref().to_string());
        self
    }

    /// Processing environment. It will be used to take right queries from config file.
    pub fn env<S: AsRef<str>>(&mut self, env: S) -> &mut Self {
        self.env = Some(env.as_ref().to_string());
        self
    }

    /// File or directory path for looking for configuration file.
    pub fn path<S: AsRef<str>>(&mut self, path: S) -> &mut Self {
        self.path = Some(path.as_ref().to_string());
        self
    }

    /// Throw error on missing env.
    pub fn throw_on_missing(&mut self, flag: bool) -> &mut Self {
        self.throw_on_missing = flag;
        self
    }
}