darklua_core/frontend/
options.rs

1use std::path::{Path, PathBuf};
2
3use super::configuration::{Configuration, GeneratorParameters};
4
5/// Options for configuring the darklua process function. This is not
6/// the [`Configuration`] data itself.
7#[derive(Debug)]
8pub struct Options {
9    input: PathBuf,
10    config_path: Option<PathBuf>,
11    config: Option<Configuration>,
12    config_generator_override: Option<GeneratorParameters>,
13    output: Option<PathBuf>,
14    fail_fast: bool,
15}
16
17impl Options {
18    /// Creates a new options instance with the specified input path.
19    pub fn new(input: impl Into<PathBuf>) -> Self {
20        Self {
21            input: input.into(),
22            config_path: None,
23            config: None,
24            output: None,
25            fail_fast: false,
26            config_generator_override: None,
27        }
28    }
29
30    /// Sets the path to the configuration file.
31    pub fn with_configuration_at(mut self, config: impl Into<PathBuf>) -> Self {
32        self.config_path = Some(config.into());
33        self
34    }
35
36    /// Sets the configuration directly.
37    pub fn with_configuration(mut self, config: Configuration) -> Self {
38        self.config = Some(config);
39        self
40    }
41
42    /// Sets the output path.
43    pub fn with_output(mut self, output: impl Into<PathBuf>) -> Self {
44        self.output = Some(output.into());
45        self
46    }
47
48    /// Enables fail-fast mode.
49    ///
50    /// When fail-fast is enabled, processing will stop immediately when an error occurs.
51    pub fn fail_fast(mut self) -> Self {
52        self.fail_fast = true;
53        self
54    }
55
56    /// Sets a generator override for the configuration.
57    ///
58    /// This will override any generator settings in the configuration file.
59    pub fn with_generator_override(mut self, generator: impl Into<GeneratorParameters>) -> Self {
60        self.config_generator_override = Some(generator.into());
61        self
62    }
63
64    /// Gets the input path.
65    pub fn input(&self) -> &Path {
66        &self.input
67    }
68
69    /// Gets the output path, if set.
70    pub fn output(&self) -> Option<&Path> {
71        self.output.as_ref().map(AsRef::as_ref)
72    }
73
74    /// Checks if fail-fast mode is enabled.
75    pub fn should_fail_fast(&self) -> bool {
76        self.fail_fast
77    }
78
79    /// Gets the configuration file path, if set.
80    pub fn configuration_path(&self) -> Option<&Path> {
81        self.config_path.as_ref().map(AsRef::as_ref)
82    }
83
84    /// Gets the generator override, if set.
85    pub fn generator_override(&self) -> Option<&GeneratorParameters> {
86        self.config_generator_override.as_ref()
87    }
88
89    /// Takes the configuration, if set.
90    ///
91    /// This removes the configuration from the options and returns it.
92    pub fn take_configuration(&mut self) -> Option<Configuration> {
93        self.config.take()
94    }
95}