xvc_config/
config_params.rs

1//! This module defines `XvcLoadParams`, a builder-style struct used to specify how Xvc should load its configuration.
2//! It allows for granular control over which configuration sources (system, user, project, environment variables, command-line) should be included.
3
4use xvc_walker::AbsolutePath;
5
6/// How should we initialize the configuration?
7///
8/// It's possible to ignore certain sources by supplying `None` to their values here.
9#[derive(Debug, Clone)]
10pub struct XvcLoadParams {
11    /// The directory where the application runs.
12    /// This can be set by various Options.
13    /// It affects how paths are handled in general.
14    pub current_dir: AbsolutePath,
15
16    /// This is Some(dir) if we run in an Xvc directory
17    /// Guid will be read from here in version 2 onwards
18    pub xvc_root_dir: Option<AbsolutePath>,
19
20    /// Should we include system configuration?
21    /// If `true`, it's read from [SYSTEM_CONFIG_DIRS].
22    pub include_system_config: bool,
23    /// Should the user's (home) config be included.
24    /// If `true`, it's read from [USER_CONFIG_DIRS].
25    pub include_user_config: bool,
26    /// Should we include the project config at .xvc/config.toml?
27    pub include_project_config: bool,
28
29    /// Should we include the local config at .xvc/config-local.toml
30    pub include_local_config: bool,
31
32    /// Where should we load the project's (public) configuration?
33    /// It's loaded in [XvcRootInner::new]
34    pub project_config_path: Option<AbsolutePath>,
35    /// Where should we load the project's (private) configuration?
36    /// It's loaded in [XvcRootInner::new]
37    /// TODO: Add a option to ignore this
38    pub local_config_path: Option<AbsolutePath>,
39    /// Should we include configuration from the environment.
40    /// If `true`, look for all variables in the form
41    ///
42    /// `XVC_group.key=value`
43    ///
44    /// from the environment and put them into the configuration.
45    pub include_environment_config: bool,
46    /// Command line configuration
47    pub command_line_config: Option<Vec<String>>,
48}
49
50impl XvcLoadParams {
51    /// Create a new blank config params
52    pub fn new(current_dir: AbsolutePath, xvc_root_dir: Option<AbsolutePath>) -> Self {
53        Self {
54            current_dir,
55            xvc_root_dir,
56            include_system_config: true,
57            include_user_config: true,
58            include_project_config: true,
59            include_local_config: true,
60            project_config_path: None,
61            local_config_path: None,
62            include_environment_config: true,
63            command_line_config: None,
64        }
65    }
66
67    /// Update include_system_config value
68    pub fn include_system_config(mut self, include_system_config: bool) -> Self {
69        self.include_system_config = include_system_config;
70        self
71    }
72
73    /// Update include_user_config value
74    pub fn include_user_config(mut self, include_user_config: bool) -> Self {
75        self.include_user_config = include_user_config;
76        self
77    }
78
79    /// Update project config path
80    pub fn project_config_path(mut self, project_config_path: Option<AbsolutePath>) -> Self {
81        self.project_config_path = project_config_path;
82        self
83    }
84
85    /// Update local config path
86    pub fn local_config_path(mut self, local_config_path: Option<AbsolutePath>) -> Self {
87        self.local_config_path = local_config_path;
88        self
89    }
90
91    /// Whether to include enviroment variables in the configuration
92    pub fn include_environment_config(mut self, include_environment_config: bool) -> Self {
93        self.include_environment_config = include_environment_config;
94        self
95    }
96
97    /// Command line config from key=value definitions
98    pub fn command_line_config(mut self, command_line_config: Option<Vec<String>>) -> Self {
99        self.command_line_config = command_line_config;
100        self
101    }
102}