1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
use Neuxcfg;
use NeuxcfgError;
use ProjectConfig;
use Value;
/// The neuxcfg project name used by this crate.
///
/// All configuration is stored under this project identifier in the neuxcfg
/// directory (typically `~/.config/neuxcfg/age-authenticator/`).
pub const PROJECT_NAME: &str = "age-authenticator";
/// Returns a new [`Neuxcfg`] instance using the system configuration directory.
///
/// This is a thin wrapper around [`Neuxcfg::new`] to avoid forcing users to
/// depend directly on `neuxcfg`.
///
/// # Errors
///
/// Returns [`NeuxcfgError::ConfigDirNotFound`] if the system config directory
/// cannot be determined.
/// Initializes the configuration store for this crate.
///
/// Creates the neuxcfg root directory and global config if they do not exist,
/// and ensures the `"age-authenticator"` project is registered.
///
/// Call this once at application startup before using other config functions.
///
/// # Errors
///
/// Returns [`NeuxcfgError`] variants for I/O failures or invalid project names.
///
/// # Examples
///
/// ```no_run
/// use age_setup::config::init;
///
/// init()?;
/// println!("Configuration store initialized.");
/// # Ok::<(), neuxcfg::NeuxcfgError>(())
/// ```
/// Loads the complete project configuration from the persistent store.
///
/// # Errors
///
/// Returns [`NeuxcfgError::ProjectNotFound`] if the project has not been
/// initialized. Call [`init`] first.
///
/// # Examples
///
/// ```no_run
/// use age_setup::config::{init, load_config};
///
/// init()?;
/// let config = load_config()?;
/// println!("Project path: {}", config.project.path);
/// # Ok::<(), neuxcfg::NeuxcfgError>(())
/// ```
/// Overwrites the entire project configuration.
///
/// A backup of the previous configuration is created automatically by neuxcfg.
///
/// # Errors
///
/// Returns [`NeuxcfgError::ProjectNotFound`] if the project has not been
/// initialized, or validation errors for invalid extra fields.
///
/// # Examples
///
/// ```no_run
/// use age_setup::config::{init, load_config, save_config};
///
/// init()?;
/// let mut config = load_config()?;
/// config.project.path = "/new/path".into();
/// save_config(&config)?;
/// # Ok::<(), neuxcfg::NeuxcfgError>(())
/// ```
/// Applies a partial update to the project configuration via deep merge.
///
/// Only the provided keys are modified; all other keys remain unchanged.
///
/// # Parameters
///
/// * `delta` – A [`toml::Value`] (usually a table) to merge into the existing config.
///
/// # Errors
///
/// Returns [`NeuxcfgError::ProjectNotFound`] if the project has not been
/// initialized, or validation/TOML parse errors.
///
/// # Examples
///
/// ```no_run
/// use age_setup::config::{init, update_config};
/// use toml::toml;
///
/// init()?;
/// let delta = toml! {
/// [project]
/// custom_setting = "enabled"
/// };
/// update_config(toml::Value::Table(delta))?;
/// # Ok::<(), neuxcfg::NeuxcfgError>(())
/// ```
/// Sets a single extra field in the project configuration.
///
/// This is a convenience wrapper around [`load_config`] and [`save_config`].
///
/// # Parameters
///
/// * `key` – The extra field name (must not start with `_` or contain `.`).
/// * `value` – A [`toml::Value`] to store.
///
/// # Errors
///
/// Returns [`NeuxcfgError`] variants from loading, validation, or saving.
///
/// # Examples
///
/// ```no_run
/// use age_setup::config::{init, set_extra};
/// use toml::Value;
///
/// init()?;
/// set_extra("api_endpoint", Value::String("https://api.example.com".into()))?;
/// # Ok::<(), neuxcfg::NeuxcfgError>(())
/// ```
/// Retrieves a single extra field from the project configuration.
///
/// Returns `None` if the key does not exist.
///
/// # Parameters
///
/// * `key` – The extra field name to look up.
///
/// # Errors
///
/// Returns [`NeuxcfgError`] variants from loading the configuration.
///
/// # Examples
///
/// ```no_run
/// use age_setup::config::{init, set_extra, get_extra};
/// use toml::Value;
///
/// init()?;
/// set_extra("theme", Value::String("dark".into()))?;
/// let theme = get_extra("theme")?;
/// assert_eq!(theme, Some(Value::String("dark".into())));
/// # Ok::<(), neuxcfg::NeuxcfgError>(())
/// ```