darklua_core/frontend/
options.rs

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
use std::path::{Path, PathBuf};

use super::configuration::{Configuration, GeneratorParameters};

#[derive(Debug)]
pub struct Options {
    input: PathBuf,
    config_path: Option<PathBuf>,
    config: Option<Configuration>,
    config_generator_override: Option<GeneratorParameters>,
    output: Option<PathBuf>,
    fail_fast: bool,
}

impl Options {
    pub fn new(input: impl Into<PathBuf>) -> Self {
        Self {
            input: input.into(),
            config_path: None,
            config: None,
            output: None,
            fail_fast: false,
            config_generator_override: None,
        }
    }

    pub fn with_configuration_at(mut self, config: impl Into<PathBuf>) -> Self {
        self.config_path = Some(config.into());
        self
    }

    pub fn with_configuration(mut self, config: Configuration) -> Self {
        self.config = Some(config);
        self
    }

    pub fn with_output(mut self, output: impl Into<PathBuf>) -> Self {
        self.output = Some(output.into());
        self
    }

    pub fn fail_fast(mut self) -> Self {
        self.fail_fast = true;
        self
    }

    pub fn with_generator_override(mut self, generator: impl Into<GeneratorParameters>) -> Self {
        self.config_generator_override = Some(generator.into());
        self
    }

    pub fn input(&self) -> &Path {
        &self.input
    }

    pub fn output(&self) -> Option<&Path> {
        self.output.as_ref().map(AsRef::as_ref)
    }

    pub fn should_fail_fast(&self) -> bool {
        self.fail_fast
    }

    pub fn configuration_path(&self) -> Option<&Path> {
        self.config_path.as_ref().map(AsRef::as_ref)
    }

    pub fn generator_override(&self) -> Option<&GeneratorParameters> {
        self.config_generator_override.as_ref()
    }

    pub fn take_configuration(&mut self) -> Option<Configuration> {
        self.config.take()
    }
}