summaryrefslogtreecommitdiffstats
path: root/vendor/gix/src/config/tree/mod.rs
blob: b378b8c49ca23aceac64c34dee73ebafdd2ce239 (plain)
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
//! The tree of supported configuration values for use in [`config_overrides`][crate::open::Options::config_overrides()]
//! or for validating and transforming well-known configuration values.
//!
//! It can also be used to traverse all implemented keys and to validate values before usage as configuration overrides.
//!
//! ### Leniency
//!
//! When validating values, we don't apply leniency here which is left to the caller. Leniency is an application defined configuration
//! to ignore errors on non-security related values, which might make applications more resilient towards misconfiguration.
pub(crate) mod root {
    use super::sections;
    use crate::config::tree::Section;

    /// The root of the configuration tree, suitable to discover all sub-sections at runtime or compile time.
    #[derive(Copy, Clone, Default)]
    pub struct Tree;

    impl Tree {
        /// The `author` section.
        pub const AUTHOR: sections::Author = sections::Author;
        /// The `branch` section.
        pub const BRANCH: sections::Branch = sections::Branch;
        /// The `checkout` section.
        pub const CHECKOUT: sections::Checkout = sections::Checkout;
        /// The `clone` section.
        pub const CLONE: sections::Clone = sections::Clone;
        /// The `committer` section.
        pub const COMMITTER: sections::Committer = sections::Committer;
        /// The `core` section.
        pub const CORE: sections::Core = sections::Core;
        /// The `credential` section.
        pub const CREDENTIAL: sections::Credential = sections::Credential;
        /// The `diff` section.
        pub const DIFF: sections::Diff = sections::Diff;
        /// The `extensions` section.
        pub const EXTENSIONS: sections::Extensions = sections::Extensions;
        /// The `gitoxide` section.
        pub const GITOXIDE: sections::Gitoxide = sections::Gitoxide;
        /// The `http` section.
        pub const HTTP: sections::Http = sections::Http;
        /// The `index` section.
        pub const INDEX: sections::Index = sections::Index;
        /// The `init` section.
        pub const INIT: sections::Init = sections::Init;
        /// The `pack` section.
        pub const PACK: sections::Pack = sections::Pack;
        /// The `protocol` section.
        pub const PROTOCOL: sections::Protocol = sections::Protocol;
        /// The `remote` section.
        pub const REMOTE: sections::Remote = sections::Remote;
        /// The `safe` section.
        pub const SAFE: sections::Safe = sections::Safe;
        /// The `ssh` section.
        pub const SSH: sections::Ssh = sections::Ssh;
        /// The `user` section.
        pub const USER: sections::User = sections::User;
        /// The `url` section.
        pub const URL: sections::Url = sections::Url;

        /// List all available sections.
        pub fn sections(&self) -> &[&dyn Section] {
            &[
                &Self::AUTHOR,
                &Self::BRANCH,
                &Self::CHECKOUT,
                &Self::CLONE,
                &Self::COMMITTER,
                &Self::CORE,
                &Self::CREDENTIAL,
                &Self::DIFF,
                &Self::EXTENSIONS,
                &Self::GITOXIDE,
                &Self::HTTP,
                &Self::INDEX,
                &Self::INIT,
                &Self::PACK,
                &Self::PROTOCOL,
                &Self::REMOTE,
                &Self::SAFE,
                &Self::SSH,
                &Self::USER,
                &Self::URL,
            ]
        }
    }
}

mod sections;
pub use sections::{
    branch, checkout, core, credential, diff, extensions, gitoxide, http, index, protocol, remote, ssh, Author, Branch,
    Checkout, Clone, Committer, Core, Credential, Diff, Extensions, Gitoxide, Http, Index, Init, Pack, Protocol,
    Remote, Safe, Ssh, Url, User,
};

/// Generic value implementations for static instantiation.
pub mod keys;

///
pub mod key {
    ///
    pub mod validate {
        /// The error returned by [Key::validate()][crate::config::tree::Key::validate()].
        #[derive(Debug, thiserror::Error)]
        #[error(transparent)]
        #[allow(missing_docs)]
        pub struct Error {
            #[from]
            source: Box<dyn std::error::Error + Send + Sync + 'static>,
        }
    }
    ///
    pub mod validate_assignment {
        /// The error returned by [Key::validated_assignment*()][crate::config::tree::Key::validated_assignment_fmt()].
        #[derive(Debug, thiserror::Error)]
        #[allow(missing_docs)]
        pub enum Error {
            #[error("Failed to validate the value to be assigned to this key")]
            Validate(#[from] super::validate::Error),
            #[error("{message}")]
            Name { message: String },
        }
    }
}

mod traits;
pub use traits::{Key, Link, Note, Section, SubSectionRequirement};