author | Raphaël Gomès <rgomes@octobus.net> |
Mon, 04 Nov 2024 15:17:54 +0100 | |
changeset 52310 | a876ab6c3fd5 |
parent 51851 | 0dbf6a5ccf5f |
permissions | -rw-r--r-- |
50763
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
1 |
//! Code for parsing default Mercurial config items. |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
2 |
use itertools::Itertools; |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
3 |
use serde::Deserialize; |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
4 |
|
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
5 |
use crate::{errors::HgError, exit_codes, FastHashMap}; |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
6 |
|
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
7 |
/// Corresponds to the structure of `mercurial/configitems.toml`. |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
8 |
#[derive(Debug, Deserialize)] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
9 |
pub struct ConfigItems { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
10 |
items: Vec<DefaultConfigItem>, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
11 |
templates: FastHashMap<String, Vec<TemplateItem>>, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
12 |
#[serde(rename = "template-applications")] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
13 |
template_applications: Vec<TemplateApplication>, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
14 |
} |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
15 |
|
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
16 |
/// Corresponds to a config item declaration in `mercurial/configitems.toml`. |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
17 |
#[derive(Clone, Debug, PartialEq, Deserialize)] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
18 |
#[serde(try_from = "RawDefaultConfigItem")] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
19 |
pub struct DefaultConfigItem { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
20 |
/// Section of the config the item is in (e.g. `[merge-tools]`) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
21 |
section: String, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
22 |
/// Name of the item (e.g. `meld.gui`) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
23 |
name: String, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
24 |
/// Default value (can be dynamic, see [`DefaultConfigItemType`]) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
25 |
default: Option<DefaultConfigItemType>, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
26 |
/// If the config option is generic (e.g. `merge-tools.*`), defines |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
27 |
/// the priority of this item relative to other generic items. |
52310
a876ab6c3fd5
rust: fix `cargo doc` warnings
Raphaël Gomès <rgomes@octobus.net>
parents:
51851
diff
changeset
|
28 |
/// If we're looking for `<pattern>`, then all generic items within the |
a876ab6c3fd5
rust: fix `cargo doc` warnings
Raphaël Gomès <rgomes@octobus.net>
parents:
51851
diff
changeset
|
29 |
/// same section will be sorted by order of priority, and the first |
a876ab6c3fd5
rust: fix `cargo doc` warnings
Raphaël Gomès <rgomes@octobus.net>
parents:
51851
diff
changeset
|
30 |
/// regex match against `name` is returned. |
50763
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
31 |
#[serde(default)] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
32 |
priority: Option<isize>, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
33 |
/// Aliases, if any. Each alias is a tuple of `(section, name)` for each |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
34 |
/// option that is aliased to this one. |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
35 |
#[serde(default)] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
36 |
alias: Vec<(String, String)>, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
37 |
/// Whether the config item is marked as experimental |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
38 |
#[serde(default)] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
39 |
experimental: bool, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
40 |
/// The (possibly empty) docstring for the item |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
41 |
#[serde(default)] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
42 |
documentation: String, |
50765
7f8f6fe13fa9
configitems: move blackbox's config items to the new configitems.toml
Raphaël Gomès <rgomes@octobus.net>
parents:
50763
diff
changeset
|
43 |
/// Whether the item is part of an in-core extension. This allows us to |
7f8f6fe13fa9
configitems: move blackbox's config items to the new configitems.toml
Raphaël Gomès <rgomes@octobus.net>
parents:
50763
diff
changeset
|
44 |
/// hide them if the extension is not enabled, to preserve legacy |
7f8f6fe13fa9
configitems: move blackbox's config items to the new configitems.toml
Raphaël Gomès <rgomes@octobus.net>
parents:
50763
diff
changeset
|
45 |
/// behavior. |
7f8f6fe13fa9
configitems: move blackbox's config items to the new configitems.toml
Raphaël Gomès <rgomes@octobus.net>
parents:
50763
diff
changeset
|
46 |
#[serde(default)] |
7f8f6fe13fa9
configitems: move blackbox's config items to the new configitems.toml
Raphaël Gomès <rgomes@octobus.net>
parents:
50763
diff
changeset
|
47 |
in_core_extension: Option<String>, |
50763
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
48 |
} |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
49 |
|
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
50 |
/// Corresponds to the raw (i.e. on disk) structure of config items. Used as |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
51 |
/// an intermediate step in deserialization. |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
52 |
#[derive(Clone, Debug, Deserialize)] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
53 |
struct RawDefaultConfigItem { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
54 |
section: String, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
55 |
name: String, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
56 |
default: Option<toml::Value>, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
57 |
#[serde(rename = "default-type")] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
58 |
default_type: Option<String>, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
59 |
#[serde(default)] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
60 |
priority: isize, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
61 |
#[serde(default)] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
62 |
generic: bool, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
63 |
#[serde(default)] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
64 |
alias: Vec<(String, String)>, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
65 |
#[serde(default)] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
66 |
experimental: bool, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
67 |
#[serde(default)] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
68 |
documentation: String, |
50765
7f8f6fe13fa9
configitems: move blackbox's config items to the new configitems.toml
Raphaël Gomès <rgomes@octobus.net>
parents:
50763
diff
changeset
|
69 |
#[serde(default)] |
7f8f6fe13fa9
configitems: move blackbox's config items to the new configitems.toml
Raphaël Gomès <rgomes@octobus.net>
parents:
50763
diff
changeset
|
70 |
in_core_extension: Option<String>, |
50763
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
71 |
} |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
72 |
|
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
73 |
impl TryFrom<RawDefaultConfigItem> for DefaultConfigItem { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
74 |
type Error = HgError; |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
75 |
|
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
76 |
fn try_from(value: RawDefaultConfigItem) -> Result<Self, Self::Error> { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
77 |
Ok(Self { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
78 |
section: value.section, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
79 |
name: value.name, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
80 |
default: raw_default_to_concrete( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
81 |
value.default_type, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
82 |
value.default, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
83 |
)?, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
84 |
priority: if value.generic { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
85 |
Some(value.priority) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
86 |
} else { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
87 |
None |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
88 |
}, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
89 |
alias: value.alias, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
90 |
experimental: value.experimental, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
91 |
documentation: value.documentation, |
50765
7f8f6fe13fa9
configitems: move blackbox's config items to the new configitems.toml
Raphaël Gomès <rgomes@octobus.net>
parents:
50763
diff
changeset
|
92 |
in_core_extension: value.in_core_extension, |
50763
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
93 |
}) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
94 |
} |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
95 |
} |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
96 |
|
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
97 |
impl DefaultConfigItem { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
98 |
fn is_generic(&self) -> bool { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
99 |
self.priority.is_some() |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
100 |
} |
50765
7f8f6fe13fa9
configitems: move blackbox's config items to the new configitems.toml
Raphaël Gomès <rgomes@octobus.net>
parents:
50763
diff
changeset
|
101 |
|
7f8f6fe13fa9
configitems: move blackbox's config items to the new configitems.toml
Raphaël Gomès <rgomes@octobus.net>
parents:
50763
diff
changeset
|
102 |
pub fn in_core_extension(&self) -> Option<&str> { |
7f8f6fe13fa9
configitems: move blackbox's config items to the new configitems.toml
Raphaël Gomès <rgomes@octobus.net>
parents:
50763
diff
changeset
|
103 |
self.in_core_extension.as_deref() |
7f8f6fe13fa9
configitems: move blackbox's config items to the new configitems.toml
Raphaël Gomès <rgomes@octobus.net>
parents:
50763
diff
changeset
|
104 |
} |
7f8f6fe13fa9
configitems: move blackbox's config items to the new configitems.toml
Raphaël Gomès <rgomes@octobus.net>
parents:
50763
diff
changeset
|
105 |
|
7f8f6fe13fa9
configitems: move blackbox's config items to the new configitems.toml
Raphaël Gomès <rgomes@octobus.net>
parents:
50763
diff
changeset
|
106 |
pub fn section(&self) -> &str { |
7f8f6fe13fa9
configitems: move blackbox's config items to the new configitems.toml
Raphaël Gomès <rgomes@octobus.net>
parents:
50763
diff
changeset
|
107 |
self.section.as_ref() |
7f8f6fe13fa9
configitems: move blackbox's config items to the new configitems.toml
Raphaël Gomès <rgomes@octobus.net>
parents:
50763
diff
changeset
|
108 |
} |
50763
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
109 |
} |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
110 |
|
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
111 |
impl<'a> TryFrom<&'a DefaultConfigItem> for Option<&'a str> { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
112 |
type Error = HgError; |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
113 |
|
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
114 |
fn try_from( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
115 |
value: &'a DefaultConfigItem, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
116 |
) -> Result<Option<&'a str>, Self::Error> { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
117 |
match &value.default { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
118 |
Some(default) => { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
119 |
let err = HgError::abort( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
120 |
format!( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
121 |
"programming error: wrong query on config item '{}.{}'", |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
122 |
value.section, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
123 |
value.name |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
124 |
), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
125 |
exit_codes::ABORT, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
126 |
Some(format!( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
127 |
"asked for '&str', type of default is '{}'", |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
128 |
default.type_str() |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
129 |
)), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
130 |
); |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
131 |
match default { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
132 |
DefaultConfigItemType::Primitive(toml::Value::String( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
133 |
s, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
134 |
)) => Ok(Some(s)), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
135 |
_ => Err(err), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
136 |
} |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
137 |
} |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
138 |
None => Ok(None), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
139 |
} |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
140 |
} |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
141 |
} |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
142 |
|
50981
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
143 |
impl<'a> TryFrom<&'a DefaultConfigItem> for Option<&'a [u8]> { |
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
144 |
type Error = HgError; |
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
145 |
|
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
146 |
fn try_from( |
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
147 |
value: &'a DefaultConfigItem, |
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
148 |
) -> Result<Option<&'a [u8]>, Self::Error> { |
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
149 |
match &value.default { |
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
150 |
Some(default) => { |
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
151 |
let err = HgError::abort( |
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
152 |
format!( |
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
153 |
"programming error: wrong query on config item '{}.{}'", |
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
154 |
value.section, |
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
155 |
value.name |
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
156 |
), |
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
157 |
exit_codes::ABORT, |
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
158 |
Some(format!( |
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
159 |
"asked for bytes, type of default is '{}', \ |
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
160 |
which cannot be interpreted as bytes", |
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
161 |
default.type_str() |
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
162 |
)), |
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
163 |
); |
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
164 |
match default { |
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
165 |
DefaultConfigItemType::Primitive(p) => { |
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
166 |
Ok(p.as_str().map(str::as_bytes)) |
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
167 |
} |
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
168 |
_ => Err(err), |
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
169 |
} |
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
170 |
} |
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
171 |
None => Ok(None), |
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
172 |
} |
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
173 |
} |
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
174 |
} |
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
175 |
|
50763
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
176 |
impl TryFrom<&DefaultConfigItem> for Option<bool> { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
177 |
type Error = HgError; |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
178 |
|
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
179 |
fn try_from(value: &DefaultConfigItem) -> Result<Self, Self::Error> { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
180 |
match &value.default { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
181 |
Some(default) => { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
182 |
let err = HgError::abort( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
183 |
format!( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
184 |
"programming error: wrong query on config item '{}.{}'", |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
185 |
value.section, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
186 |
value.name |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
187 |
), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
188 |
exit_codes::ABORT, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
189 |
Some(format!( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
190 |
"asked for 'bool', type of default is '{}'", |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
191 |
default.type_str() |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
192 |
)), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
193 |
); |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
194 |
match default { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
195 |
DefaultConfigItemType::Primitive( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
196 |
toml::Value::Boolean(b), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
197 |
) => Ok(Some(*b)), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
198 |
_ => Err(err), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
199 |
} |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
200 |
} |
50983
8343947af6a7
rust-config: fix incorrect coercion of null values to false
Raphaël Gomès <rgomes@octobus.net>
parents:
50981
diff
changeset
|
201 |
None => Ok(None), |
50763
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
202 |
} |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
203 |
} |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
204 |
} |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
205 |
|
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
206 |
impl TryFrom<&DefaultConfigItem> for Option<u32> { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
207 |
type Error = HgError; |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
208 |
|
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
209 |
fn try_from(value: &DefaultConfigItem) -> Result<Self, Self::Error> { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
210 |
match &value.default { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
211 |
Some(default) => { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
212 |
let err = HgError::abort( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
213 |
format!( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
214 |
"programming error: wrong query on config item '{}.{}'", |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
215 |
value.section, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
216 |
value.name |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
217 |
), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
218 |
exit_codes::ABORT, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
219 |
Some(format!( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
220 |
"asked for 'u32', type of default is '{}'", |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
221 |
default.type_str() |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
222 |
)), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
223 |
); |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
224 |
match default { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
225 |
DefaultConfigItemType::Primitive( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
226 |
toml::Value::Integer(b), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
227 |
) => { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
228 |
Ok(Some((*b).try_into().expect("TOML integer to u32"))) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
229 |
} |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
230 |
_ => Err(err), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
231 |
} |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
232 |
} |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
233 |
None => Ok(None), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
234 |
} |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
235 |
} |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
236 |
} |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
237 |
|
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
238 |
impl TryFrom<&DefaultConfigItem> for Option<u64> { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
239 |
type Error = HgError; |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
240 |
|
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
241 |
fn try_from(value: &DefaultConfigItem) -> Result<Self, Self::Error> { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
242 |
match &value.default { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
243 |
Some(default) => { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
244 |
let err = HgError::abort( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
245 |
format!( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
246 |
"programming error: wrong query on config item '{}.{}'", |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
247 |
value.section, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
248 |
value.name |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
249 |
), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
250 |
exit_codes::ABORT, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
251 |
Some(format!( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
252 |
"asked for 'u64', type of default is '{}'", |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
253 |
default.type_str() |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
254 |
)), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
255 |
); |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
256 |
match default { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
257 |
DefaultConfigItemType::Primitive( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
258 |
toml::Value::Integer(b), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
259 |
) => { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
260 |
Ok(Some((*b).try_into().expect("TOML integer to u64"))) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
261 |
} |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
262 |
_ => Err(err), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
263 |
} |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
264 |
} |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
265 |
None => Ok(None), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
266 |
} |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
267 |
} |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
268 |
} |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
269 |
|
51851
0dbf6a5ccf5f
rust-config: add more ways of reading the config
Raphaël Gomès <rgomes@octobus.net>
parents:
50983
diff
changeset
|
270 |
impl TryFrom<&DefaultConfigItem> for Option<i64> { |
0dbf6a5ccf5f
rust-config: add more ways of reading the config
Raphaël Gomès <rgomes@octobus.net>
parents:
50983
diff
changeset
|
271 |
type Error = HgError; |
0dbf6a5ccf5f
rust-config: add more ways of reading the config
Raphaël Gomès <rgomes@octobus.net>
parents:
50983
diff
changeset
|
272 |
|
0dbf6a5ccf5f
rust-config: add more ways of reading the config
Raphaël Gomès <rgomes@octobus.net>
parents:
50983
diff
changeset
|
273 |
fn try_from(value: &DefaultConfigItem) -> Result<Self, Self::Error> { |
0dbf6a5ccf5f
rust-config: add more ways of reading the config
Raphaël Gomès <rgomes@octobus.net>
parents:
50983
diff
changeset
|
274 |
match &value.default { |
0dbf6a5ccf5f
rust-config: add more ways of reading the config
Raphaël Gomès <rgomes@octobus.net>
parents:
50983
diff
changeset
|
275 |
Some(default) => { |
0dbf6a5ccf5f
rust-config: add more ways of reading the config
Raphaël Gomès <rgomes@octobus.net>
parents:
50983
diff
changeset
|
276 |
let err = HgError::abort( |
0dbf6a5ccf5f
rust-config: add more ways of reading the config
Raphaël Gomès <rgomes@octobus.net>
parents:
50983
diff
changeset
|
277 |
format!( |
0dbf6a5ccf5f
rust-config: add more ways of reading the config
Raphaël Gomès <rgomes@octobus.net>
parents:
50983
diff
changeset
|
278 |
"programming error: wrong query on config item '{}.{}'", |
0dbf6a5ccf5f
rust-config: add more ways of reading the config
Raphaël Gomès <rgomes@octobus.net>
parents:
50983
diff
changeset
|
279 |
value.section, |
0dbf6a5ccf5f
rust-config: add more ways of reading the config
Raphaël Gomès <rgomes@octobus.net>
parents:
50983
diff
changeset
|
280 |
value.name |
0dbf6a5ccf5f
rust-config: add more ways of reading the config
Raphaël Gomès <rgomes@octobus.net>
parents:
50983
diff
changeset
|
281 |
), |
0dbf6a5ccf5f
rust-config: add more ways of reading the config
Raphaël Gomès <rgomes@octobus.net>
parents:
50983
diff
changeset
|
282 |
exit_codes::ABORT, |
0dbf6a5ccf5f
rust-config: add more ways of reading the config
Raphaël Gomès <rgomes@octobus.net>
parents:
50983
diff
changeset
|
283 |
Some(format!( |
0dbf6a5ccf5f
rust-config: add more ways of reading the config
Raphaël Gomès <rgomes@octobus.net>
parents:
50983
diff
changeset
|
284 |
"asked for 'i64', type of default is '{}'", |
0dbf6a5ccf5f
rust-config: add more ways of reading the config
Raphaël Gomès <rgomes@octobus.net>
parents:
50983
diff
changeset
|
285 |
default.type_str() |
0dbf6a5ccf5f
rust-config: add more ways of reading the config
Raphaël Gomès <rgomes@octobus.net>
parents:
50983
diff
changeset
|
286 |
)), |
0dbf6a5ccf5f
rust-config: add more ways of reading the config
Raphaël Gomès <rgomes@octobus.net>
parents:
50983
diff
changeset
|
287 |
); |
0dbf6a5ccf5f
rust-config: add more ways of reading the config
Raphaël Gomès <rgomes@octobus.net>
parents:
50983
diff
changeset
|
288 |
match default { |
0dbf6a5ccf5f
rust-config: add more ways of reading the config
Raphaël Gomès <rgomes@octobus.net>
parents:
50983
diff
changeset
|
289 |
DefaultConfigItemType::Primitive( |
0dbf6a5ccf5f
rust-config: add more ways of reading the config
Raphaël Gomès <rgomes@octobus.net>
parents:
50983
diff
changeset
|
290 |
toml::Value::Integer(b), |
0dbf6a5ccf5f
rust-config: add more ways of reading the config
Raphaël Gomès <rgomes@octobus.net>
parents:
50983
diff
changeset
|
291 |
) => Ok(Some(*b)), |
0dbf6a5ccf5f
rust-config: add more ways of reading the config
Raphaël Gomès <rgomes@octobus.net>
parents:
50983
diff
changeset
|
292 |
_ => Err(err), |
0dbf6a5ccf5f
rust-config: add more ways of reading the config
Raphaël Gomès <rgomes@octobus.net>
parents:
50983
diff
changeset
|
293 |
} |
0dbf6a5ccf5f
rust-config: add more ways of reading the config
Raphaël Gomès <rgomes@octobus.net>
parents:
50983
diff
changeset
|
294 |
} |
0dbf6a5ccf5f
rust-config: add more ways of reading the config
Raphaël Gomès <rgomes@octobus.net>
parents:
50983
diff
changeset
|
295 |
None => Ok(None), |
0dbf6a5ccf5f
rust-config: add more ways of reading the config
Raphaël Gomès <rgomes@octobus.net>
parents:
50983
diff
changeset
|
296 |
} |
0dbf6a5ccf5f
rust-config: add more ways of reading the config
Raphaël Gomès <rgomes@octobus.net>
parents:
50983
diff
changeset
|
297 |
} |
0dbf6a5ccf5f
rust-config: add more ways of reading the config
Raphaël Gomès <rgomes@octobus.net>
parents:
50983
diff
changeset
|
298 |
} |
0dbf6a5ccf5f
rust-config: add more ways of reading the config
Raphaël Gomès <rgomes@octobus.net>
parents:
50983
diff
changeset
|
299 |
|
0dbf6a5ccf5f
rust-config: add more ways of reading the config
Raphaël Gomès <rgomes@octobus.net>
parents:
50983
diff
changeset
|
300 |
impl TryFrom<&DefaultConfigItem> for Option<f64> { |
0dbf6a5ccf5f
rust-config: add more ways of reading the config
Raphaël Gomès <rgomes@octobus.net>
parents:
50983
diff
changeset
|
301 |
type Error = HgError; |
0dbf6a5ccf5f
rust-config: add more ways of reading the config
Raphaël Gomès <rgomes@octobus.net>
parents:
50983
diff
changeset
|
302 |
|
0dbf6a5ccf5f
rust-config: add more ways of reading the config
Raphaël Gomès <rgomes@octobus.net>
parents:
50983
diff
changeset
|
303 |
fn try_from(value: &DefaultConfigItem) -> Result<Self, Self::Error> { |
0dbf6a5ccf5f
rust-config: add more ways of reading the config
Raphaël Gomès <rgomes@octobus.net>
parents:
50983
diff
changeset
|
304 |
match &value.default { |
0dbf6a5ccf5f
rust-config: add more ways of reading the config
Raphaël Gomès <rgomes@octobus.net>
parents:
50983
diff
changeset
|
305 |
Some(default) => { |
0dbf6a5ccf5f
rust-config: add more ways of reading the config
Raphaël Gomès <rgomes@octobus.net>
parents:
50983
diff
changeset
|
306 |
let err = HgError::abort( |
0dbf6a5ccf5f
rust-config: add more ways of reading the config
Raphaël Gomès <rgomes@octobus.net>
parents:
50983
diff
changeset
|
307 |
format!( |
0dbf6a5ccf5f
rust-config: add more ways of reading the config
Raphaël Gomès <rgomes@octobus.net>
parents:
50983
diff
changeset
|
308 |
"programming error: wrong query on config item '{}.{}'", |
0dbf6a5ccf5f
rust-config: add more ways of reading the config
Raphaël Gomès <rgomes@octobus.net>
parents:
50983
diff
changeset
|
309 |
value.section, |
0dbf6a5ccf5f
rust-config: add more ways of reading the config
Raphaël Gomès <rgomes@octobus.net>
parents:
50983
diff
changeset
|
310 |
value.name |
0dbf6a5ccf5f
rust-config: add more ways of reading the config
Raphaël Gomès <rgomes@octobus.net>
parents:
50983
diff
changeset
|
311 |
), |
0dbf6a5ccf5f
rust-config: add more ways of reading the config
Raphaël Gomès <rgomes@octobus.net>
parents:
50983
diff
changeset
|
312 |
exit_codes::ABORT, |
0dbf6a5ccf5f
rust-config: add more ways of reading the config
Raphaël Gomès <rgomes@octobus.net>
parents:
50983
diff
changeset
|
313 |
Some(format!( |
0dbf6a5ccf5f
rust-config: add more ways of reading the config
Raphaël Gomès <rgomes@octobus.net>
parents:
50983
diff
changeset
|
314 |
"asked for 'f64', type of default is '{}'", |
0dbf6a5ccf5f
rust-config: add more ways of reading the config
Raphaël Gomès <rgomes@octobus.net>
parents:
50983
diff
changeset
|
315 |
default.type_str() |
0dbf6a5ccf5f
rust-config: add more ways of reading the config
Raphaël Gomès <rgomes@octobus.net>
parents:
50983
diff
changeset
|
316 |
)), |
0dbf6a5ccf5f
rust-config: add more ways of reading the config
Raphaël Gomès <rgomes@octobus.net>
parents:
50983
diff
changeset
|
317 |
); |
0dbf6a5ccf5f
rust-config: add more ways of reading the config
Raphaël Gomès <rgomes@octobus.net>
parents:
50983
diff
changeset
|
318 |
match default { |
0dbf6a5ccf5f
rust-config: add more ways of reading the config
Raphaël Gomès <rgomes@octobus.net>
parents:
50983
diff
changeset
|
319 |
DefaultConfigItemType::Primitive(toml::Value::Float( |
0dbf6a5ccf5f
rust-config: add more ways of reading the config
Raphaël Gomès <rgomes@octobus.net>
parents:
50983
diff
changeset
|
320 |
b, |
0dbf6a5ccf5f
rust-config: add more ways of reading the config
Raphaël Gomès <rgomes@octobus.net>
parents:
50983
diff
changeset
|
321 |
)) => Ok(Some(*b)), |
0dbf6a5ccf5f
rust-config: add more ways of reading the config
Raphaël Gomès <rgomes@octobus.net>
parents:
50983
diff
changeset
|
322 |
_ => Err(err), |
0dbf6a5ccf5f
rust-config: add more ways of reading the config
Raphaël Gomès <rgomes@octobus.net>
parents:
50983
diff
changeset
|
323 |
} |
0dbf6a5ccf5f
rust-config: add more ways of reading the config
Raphaël Gomès <rgomes@octobus.net>
parents:
50983
diff
changeset
|
324 |
} |
0dbf6a5ccf5f
rust-config: add more ways of reading the config
Raphaël Gomès <rgomes@octobus.net>
parents:
50983
diff
changeset
|
325 |
None => Ok(None), |
0dbf6a5ccf5f
rust-config: add more ways of reading the config
Raphaël Gomès <rgomes@octobus.net>
parents:
50983
diff
changeset
|
326 |
} |
0dbf6a5ccf5f
rust-config: add more ways of reading the config
Raphaël Gomès <rgomes@octobus.net>
parents:
50983
diff
changeset
|
327 |
} |
0dbf6a5ccf5f
rust-config: add more ways of reading the config
Raphaël Gomès <rgomes@octobus.net>
parents:
50983
diff
changeset
|
328 |
} |
0dbf6a5ccf5f
rust-config: add more ways of reading the config
Raphaël Gomès <rgomes@octobus.net>
parents:
50983
diff
changeset
|
329 |
|
50763
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
330 |
/// Allows abstracting over more complex default values than just primitives. |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
331 |
/// The former `configitems.py` contained some dynamic code that is encoded |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
332 |
/// in this enum. |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
333 |
#[derive(Debug, PartialEq, Clone, Deserialize)] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
334 |
pub enum DefaultConfigItemType { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
335 |
/// Some primitive type (string, integer, boolean) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
336 |
Primitive(toml::Value), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
337 |
/// A dynamic value that will be given by the code at runtime |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
338 |
Dynamic, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
339 |
/// An lazily-returned array (possibly only relevant in the Python impl) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
340 |
/// Example: `lambda: [b"zstd", b"zlib"]` |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
341 |
Lambda(Vec<String>), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
342 |
/// For now, a special case for `web.encoding` that points to the |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
343 |
/// `encoding.encoding` module in the Python impl so that local encoding |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
344 |
/// is correctly resolved at runtime |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
345 |
LazyModule(String), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
346 |
ListType, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
347 |
} |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
348 |
|
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
349 |
impl DefaultConfigItemType { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
350 |
pub fn type_str(&self) -> &str { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
351 |
match self { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
352 |
DefaultConfigItemType::Primitive(primitive) => { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
353 |
primitive.type_str() |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
354 |
} |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
355 |
DefaultConfigItemType::Dynamic => "dynamic", |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
356 |
DefaultConfigItemType::Lambda(_) => "lambda", |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
357 |
DefaultConfigItemType::LazyModule(_) => "lazy_module", |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
358 |
DefaultConfigItemType::ListType => "list_type", |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
359 |
} |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
360 |
} |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
361 |
} |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
362 |
|
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
363 |
/// Most of the fields are shared with [`DefaultConfigItem`]. |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
364 |
#[derive(Debug, Clone, Deserialize)] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
365 |
#[serde(try_from = "RawTemplateItem")] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
366 |
struct TemplateItem { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
367 |
suffix: String, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
368 |
default: Option<DefaultConfigItemType>, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
369 |
priority: Option<isize>, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
370 |
#[serde(default)] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
371 |
alias: Vec<(String, String)>, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
372 |
#[serde(default)] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
373 |
experimental: bool, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
374 |
#[serde(default)] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
375 |
documentation: String, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
376 |
} |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
377 |
|
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
378 |
/// Corresponds to the raw (i.e. on disk) representation of a template item. |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
379 |
/// Used as an intermediate step in deserialization. |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
380 |
#[derive(Clone, Debug, Deserialize)] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
381 |
struct RawTemplateItem { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
382 |
suffix: String, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
383 |
default: Option<toml::Value>, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
384 |
#[serde(rename = "default-type")] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
385 |
default_type: Option<String>, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
386 |
#[serde(default)] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
387 |
priority: isize, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
388 |
#[serde(default)] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
389 |
generic: bool, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
390 |
#[serde(default)] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
391 |
alias: Vec<(String, String)>, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
392 |
#[serde(default)] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
393 |
experimental: bool, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
394 |
#[serde(default)] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
395 |
documentation: String, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
396 |
} |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
397 |
|
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
398 |
impl TemplateItem { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
399 |
fn into_default_item( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
400 |
self, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
401 |
application: TemplateApplication, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
402 |
) -> DefaultConfigItem { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
403 |
DefaultConfigItem { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
404 |
section: application.section, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
405 |
name: application |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
406 |
.prefix |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
407 |
.map(|prefix| format!("{}.{}", prefix, self.suffix)) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
408 |
.unwrap_or(self.suffix), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
409 |
default: self.default, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
410 |
priority: self.priority, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
411 |
alias: self.alias, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
412 |
experimental: self.experimental, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
413 |
documentation: self.documentation, |
50765
7f8f6fe13fa9
configitems: move blackbox's config items to the new configitems.toml
Raphaël Gomès <rgomes@octobus.net>
parents:
50763
diff
changeset
|
414 |
in_core_extension: None, |
50763
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
415 |
} |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
416 |
} |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
417 |
} |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
418 |
|
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
419 |
impl TryFrom<RawTemplateItem> for TemplateItem { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
420 |
type Error = HgError; |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
421 |
|
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
422 |
fn try_from(value: RawTemplateItem) -> Result<Self, Self::Error> { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
423 |
Ok(Self { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
424 |
suffix: value.suffix, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
425 |
default: raw_default_to_concrete( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
426 |
value.default_type, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
427 |
value.default, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
428 |
)?, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
429 |
priority: if value.generic { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
430 |
Some(value.priority) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
431 |
} else { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
432 |
None |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
433 |
}, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
434 |
alias: value.alias, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
435 |
experimental: value.experimental, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
436 |
documentation: value.documentation, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
437 |
}) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
438 |
} |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
439 |
} |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
440 |
|
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
441 |
/// Transforms the on-disk string-based representation of complex default types |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
442 |
/// to the concrete [`DefaultconfigItemType`]. |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
443 |
fn raw_default_to_concrete( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
444 |
default_type: Option<String>, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
445 |
default: Option<toml::Value>, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
446 |
) -> Result<Option<DefaultConfigItemType>, HgError> { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
447 |
Ok(match default_type.as_deref() { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
448 |
None => default.as_ref().map(|default| { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
449 |
DefaultConfigItemType::Primitive(default.to_owned()) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
450 |
}), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
451 |
Some("dynamic") => Some(DefaultConfigItemType::Dynamic), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
452 |
Some("list_type") => Some(DefaultConfigItemType::ListType), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
453 |
Some("lambda") => match &default { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
454 |
Some(default) => Some(DefaultConfigItemType::Lambda( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
455 |
default.to_owned().try_into().map_err(|e| { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
456 |
HgError::abort( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
457 |
e.to_string(), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
458 |
exit_codes::ABORT, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
459 |
Some("Check 'mercurial/configitems.toml'".into()), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
460 |
) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
461 |
})?, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
462 |
)), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
463 |
None => { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
464 |
return Err(HgError::abort( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
465 |
"lambda defined with no return value".to_string(), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
466 |
exit_codes::ABORT, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
467 |
Some("Check 'mercurial/configitems.toml'".into()), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
468 |
)) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
469 |
} |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
470 |
}, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
471 |
Some("lazy_module") => match &default { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
472 |
Some(default) => { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
473 |
Some(DefaultConfigItemType::LazyModule(match default { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
474 |
toml::Value::String(module) => module.to_owned(), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
475 |
_ => { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
476 |
return Err(HgError::abort( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
477 |
"lazy_module module name should be a string" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
478 |
.to_string(), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
479 |
exit_codes::ABORT, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
480 |
Some("Check 'mercurial/configitems.toml'".into()), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
481 |
)) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
482 |
} |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
483 |
})) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
484 |
} |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
485 |
None => { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
486 |
return Err(HgError::abort( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
487 |
"lazy_module should have a default value".to_string(), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
488 |
exit_codes::ABORT, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
489 |
Some("Check 'mercurial/configitems.toml'".into()), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
490 |
)) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
491 |
} |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
492 |
}, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
493 |
Some(invalid) => { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
494 |
return Err(HgError::abort( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
495 |
format!("invalid default_type '{}'", invalid), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
496 |
exit_codes::ABORT, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
497 |
Some("Check 'mercurial/configitems.toml'".into()), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
498 |
)) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
499 |
} |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
500 |
}) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
501 |
} |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
502 |
|
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
503 |
#[derive(Debug, Clone, Deserialize)] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
504 |
struct TemplateApplication { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
505 |
template: String, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
506 |
section: String, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
507 |
#[serde(default)] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
508 |
prefix: Option<String>, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
509 |
} |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
510 |
|
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
511 |
/// Represents the (dynamic) set of default core Mercurial config items from |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
512 |
/// `mercurial/configitems.toml`. |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
513 |
#[derive(Clone, Debug, Default)] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
514 |
pub struct DefaultConfig { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
515 |
/// Mapping of section -> (mapping of name -> item) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
516 |
items: FastHashMap<String, FastHashMap<String, DefaultConfigItem>>, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
517 |
} |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
518 |
|
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
519 |
impl DefaultConfig { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
520 |
pub fn empty() -> DefaultConfig { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
521 |
Self { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
522 |
items: Default::default(), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
523 |
} |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
524 |
} |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
525 |
|
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
526 |
/// Returns `Self`, given the contents of `mercurial/configitems.toml` |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
527 |
#[logging_timer::time("trace")] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
528 |
pub fn from_contents(contents: &str) -> Result<Self, HgError> { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
529 |
let mut from_file: ConfigItems = |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
530 |
toml::from_str(contents).map_err(|e| { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
531 |
HgError::abort( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
532 |
e.to_string(), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
533 |
exit_codes::ABORT, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
534 |
Some("Check 'mercurial/configitems.toml'".into()), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
535 |
) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
536 |
})?; |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
537 |
|
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
538 |
let mut flat_items = from_file.items; |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
539 |
|
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
540 |
for application in from_file.template_applications.drain(..) { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
541 |
match from_file.templates.get(&application.template) { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
542 |
None => return Err( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
543 |
HgError::abort( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
544 |
format!( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
545 |
"template application refers to undefined template '{}'", |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
546 |
application.template |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
547 |
), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
548 |
exit_codes::ABORT, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
549 |
Some("Check 'mercurial/configitems.toml'".into()) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
550 |
) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
551 |
), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
552 |
Some(template_items) => { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
553 |
for template_item in template_items { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
554 |
flat_items.push( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
555 |
template_item |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
556 |
.clone() |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
557 |
.into_default_item(application.clone()), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
558 |
) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
559 |
} |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
560 |
} |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
561 |
}; |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
562 |
} |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
563 |
|
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
564 |
let items = flat_items.into_iter().fold( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
565 |
FastHashMap::default(), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
566 |
|mut acc, item| { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
567 |
acc.entry(item.section.to_owned()) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
568 |
.or_insert_with(|| { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
569 |
let mut section = FastHashMap::default(); |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
570 |
section.insert(item.name.to_owned(), item.to_owned()); |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
571 |
section |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
572 |
}) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
573 |
.insert(item.name.to_owned(), item); |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
574 |
acc |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
575 |
}, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
576 |
); |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
577 |
|
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
578 |
Ok(Self { items }) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
579 |
} |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
580 |
|
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
581 |
/// Return the default config item that matches `section` and `item`. |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
582 |
pub fn get( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
583 |
&self, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
584 |
section: &[u8], |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
585 |
item: &[u8], |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
586 |
) -> Option<&DefaultConfigItem> { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
587 |
// Core items must be valid UTF-8 |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
588 |
let section = String::from_utf8_lossy(section); |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
589 |
let section_map = self.items.get(section.as_ref())?; |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
590 |
let item_name_lossy = String::from_utf8_lossy(item); |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
591 |
match section_map.get(item_name_lossy.as_ref()) { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
592 |
Some(item) => Some(item), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
593 |
None => { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
594 |
for generic_item in section_map |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
595 |
.values() |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
596 |
.filter(|item| item.is_generic()) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
597 |
.sorted_by_key(|item| match item.priority { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
598 |
Some(priority) => (priority, &item.name), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
599 |
_ => unreachable!(), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
600 |
}) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
601 |
{ |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
602 |
if regex::bytes::Regex::new(&generic_item.name) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
603 |
.expect("invalid regex in configitems") |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
604 |
.is_match(item) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
605 |
{ |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
606 |
return Some(generic_item); |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
607 |
} |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
608 |
} |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
609 |
None |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
610 |
} |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
611 |
} |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
612 |
} |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
613 |
} |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
614 |
|
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
615 |
#[cfg(test)] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
616 |
mod tests { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
617 |
use crate::config::config_items::{ |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
618 |
DefaultConfigItem, DefaultConfigItemType, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
619 |
}; |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
620 |
|
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
621 |
use super::DefaultConfig; |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
622 |
|
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
623 |
#[test] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
624 |
fn test_config_read() { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
625 |
let contents = r#" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
626 |
[[items]] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
627 |
section = "alias" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
628 |
name = "abcd.*" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
629 |
default = 3 |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
630 |
generic = true |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
631 |
priority = -1 |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
632 |
|
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
633 |
[[items]] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
634 |
section = "alias" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
635 |
name = ".*" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
636 |
default-type = "dynamic" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
637 |
generic = true |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
638 |
|
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
639 |
[[items]] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
640 |
section = "cmdserver" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
641 |
name = "track-log" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
642 |
default-type = "lambda" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
643 |
default = [ "chgserver", "cmdserver", "repocache",] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
644 |
|
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
645 |
[[items]] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
646 |
section = "chgserver" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
647 |
name = "idletimeout" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
648 |
default = 3600 |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
649 |
|
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
650 |
[[items]] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
651 |
section = "cmdserver" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
652 |
name = "message-encodings" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
653 |
default-type = "list_type" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
654 |
|
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
655 |
[[items]] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
656 |
section = "web" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
657 |
name = "encoding" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
658 |
default-type = "lazy_module" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
659 |
default = "encoding.encoding" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
660 |
|
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
661 |
[[items]] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
662 |
section = "command-templates" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
663 |
name = "graphnode" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
664 |
alias = [["ui", "graphnodetemplate"]] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
665 |
documentation = """This is a docstring. |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
666 |
This is another line \ |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
667 |
but this is not.""" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
668 |
|
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
669 |
[[items]] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
670 |
section = "censor" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
671 |
name = "policy" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
672 |
default = "abort" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
673 |
experimental = true |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
674 |
|
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
675 |
[[template-applications]] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
676 |
template = "diff-options" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
677 |
section = "commands" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
678 |
prefix = "revert.interactive" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
679 |
|
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
680 |
[[template-applications]] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
681 |
template = "diff-options" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
682 |
section = "diff" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
683 |
|
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
684 |
[templates] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
685 |
[[templates.diff-options]] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
686 |
suffix = "nodates" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
687 |
default = false |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
688 |
|
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
689 |
[[templates.diff-options]] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
690 |
suffix = "showfunc" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
691 |
default = false |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
692 |
|
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
693 |
[[templates.diff-options]] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
694 |
suffix = "unified" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
695 |
"#; |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
696 |
let res = DefaultConfig::from_contents(contents); |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
697 |
let config = match res { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
698 |
Ok(config) => config, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
699 |
Err(e) => panic!("{}", e), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
700 |
}; |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
701 |
let expected = DefaultConfigItem { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
702 |
section: "censor".into(), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
703 |
name: "policy".into(), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
704 |
default: Some(DefaultConfigItemType::Primitive("abort".into())), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
705 |
priority: None, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
706 |
alias: vec![], |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
707 |
experimental: true, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
708 |
documentation: "".into(), |
50765
7f8f6fe13fa9
configitems: move blackbox's config items to the new configitems.toml
Raphaël Gomès <rgomes@octobus.net>
parents:
50763
diff
changeset
|
709 |
in_core_extension: None, |
50763
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
710 |
}; |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
711 |
assert_eq!(config.get(b"censor", b"policy"), Some(&expected)); |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
712 |
|
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
713 |
// Test generic priority. The `.*` pattern is wider than `abcd.*`, but |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
714 |
// `abcd.*` has priority, so it should match first. |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
715 |
let expected = DefaultConfigItem { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
716 |
section: "alias".into(), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
717 |
name: "abcd.*".into(), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
718 |
default: Some(DefaultConfigItemType::Primitive(3.into())), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
719 |
priority: Some(-1), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
720 |
alias: vec![], |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
721 |
experimental: false, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
722 |
documentation: "".into(), |
50765
7f8f6fe13fa9
configitems: move blackbox's config items to the new configitems.toml
Raphaël Gomès <rgomes@octobus.net>
parents:
50763
diff
changeset
|
723 |
in_core_extension: None, |
50763
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
724 |
}; |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
725 |
assert_eq!(config.get(b"alias", b"abcdsomething"), Some(&expected)); |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
726 |
|
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
727 |
//... but if it doesn't, we should fallback to `.*` |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
728 |
let expected = DefaultConfigItem { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
729 |
section: "alias".into(), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
730 |
name: ".*".into(), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
731 |
default: Some(DefaultConfigItemType::Dynamic), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
732 |
priority: Some(0), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
733 |
alias: vec![], |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
734 |
experimental: false, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
735 |
documentation: "".into(), |
50765
7f8f6fe13fa9
configitems: move blackbox's config items to the new configitems.toml
Raphaël Gomès <rgomes@octobus.net>
parents:
50763
diff
changeset
|
736 |
in_core_extension: None, |
50763
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
737 |
}; |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
738 |
assert_eq!(config.get(b"alias", b"something"), Some(&expected)); |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
739 |
|
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
740 |
let expected = DefaultConfigItem { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
741 |
section: "chgserver".into(), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
742 |
name: "idletimeout".into(), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
743 |
default: Some(DefaultConfigItemType::Primitive(3600.into())), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
744 |
priority: None, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
745 |
alias: vec![], |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
746 |
experimental: false, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
747 |
documentation: "".into(), |
50765
7f8f6fe13fa9
configitems: move blackbox's config items to the new configitems.toml
Raphaël Gomès <rgomes@octobus.net>
parents:
50763
diff
changeset
|
748 |
in_core_extension: None, |
50763
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
749 |
}; |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
750 |
assert_eq!(config.get(b"chgserver", b"idletimeout"), Some(&expected)); |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
751 |
|
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
752 |
let expected = DefaultConfigItem { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
753 |
section: "cmdserver".into(), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
754 |
name: "track-log".into(), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
755 |
default: Some(DefaultConfigItemType::Lambda(vec![ |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
756 |
"chgserver".into(), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
757 |
"cmdserver".into(), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
758 |
"repocache".into(), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
759 |
])), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
760 |
priority: None, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
761 |
alias: vec![], |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
762 |
experimental: false, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
763 |
documentation: "".into(), |
50765
7f8f6fe13fa9
configitems: move blackbox's config items to the new configitems.toml
Raphaël Gomès <rgomes@octobus.net>
parents:
50763
diff
changeset
|
764 |
in_core_extension: None, |
50763
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
765 |
}; |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
766 |
assert_eq!(config.get(b"cmdserver", b"track-log"), Some(&expected)); |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
767 |
|
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
768 |
let expected = DefaultConfigItem { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
769 |
section: "command-templates".into(), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
770 |
name: "graphnode".into(), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
771 |
default: None, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
772 |
priority: None, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
773 |
alias: vec![("ui".into(), "graphnodetemplate".into())], |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
774 |
experimental: false, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
775 |
documentation: |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
776 |
"This is a docstring.\nThis is another line but this is not." |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
777 |
.into(), |
50765
7f8f6fe13fa9
configitems: move blackbox's config items to the new configitems.toml
Raphaël Gomès <rgomes@octobus.net>
parents:
50763
diff
changeset
|
778 |
in_core_extension: None, |
50763
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
779 |
}; |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
780 |
assert_eq!( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
781 |
config.get(b"command-templates", b"graphnode"), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
782 |
Some(&expected) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
783 |
); |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
784 |
} |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
785 |
} |