Skip to main content

git_atomic/config/
source.rs

1use std::fmt;
2
3/// Tracks where a configuration value came from.
4#[derive(Debug, Clone, PartialEq, Eq)]
5pub enum ConfigSource {
6    /// Hardcoded default value.
7    Default,
8    /// Git config (system < global < local < worktree, merged by gix).
9    GitConfig,
10    /// `.atomic.toml` file.
11    File,
12    /// `GIT_ATOMIC_*` environment variable.
13    Env,
14    /// CLI argument (reserved — unused this phase).
15    Cli,
16}
17
18impl ConfigSource {
19    /// Short label for status output.
20    pub fn label(&self) -> &str {
21        match self {
22            ConfigSource::Default => "default",
23            ConfigSource::GitConfig => "git config",
24            ConfigSource::File => ".atomic.toml",
25            ConfigSource::Env => "env",
26            ConfigSource::Cli => "cli",
27        }
28    }
29}
30
31impl fmt::Display for ConfigSource {
32    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
33        f.write_str(self.label())
34    }
35}
36
37/// A configuration value with its provenance.
38#[derive(Debug, Clone)]
39pub struct Sourced<T> {
40    pub value: T,
41    pub source: ConfigSource,
42}
43
44impl<T> Sourced<T> {
45    pub fn new(value: T, source: ConfigSource) -> Self {
46        Self { value, source }
47    }
48}