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
//! Implementation details used by `#[derive(Layered)]`.
//!
//! **Not public API.** Nothing here is covered by this crate's SemVer
//! guarantees; it exists only so generated code has something to call. Keeping
//! the merge engine here rather than in the expansion means the logic is
//! compiled and tested once, not re-emitted per field.
use crate::;
use ArgMatches;
use ValueSource;
use DeserializeOwned;
// Re-exported so it is nameable from generated code and does not trip the
// `private_interfaces` lint in `resolve`'s signature below.
pub use crateConfigFile;
/// Load the config file named by `#[layered(file = "...")]`, once per parse.
///
/// # Errors
///
/// Returns [`LayeredError::Io`] or [`LayeredError::Parse`] if the file exists
/// but cannot be read or parsed. A missing file yields `Ok(None)`.
/// Did the user *actually* supply this argument, as opposed to clap filling in
/// a default?
///
/// This is the crate's core correctness primitive. `ValueSource::EnvVariable`
/// counts as explicit so that clap's own `#[arg(env = "...")]` support keeps
/// beating the config-file layer.
///
/// # Panics
///
/// Panics in debug builds if `id` is not a known argument. The derive only
/// emits this call for fields clap actually parses, never for `#[arg(skip)]`.
/// Resolve one field across every layer.
///
/// Precedence: explicit CLI flag > environment variable > config file > default.
/// `env_var` is `None` when the field opts out with `no_env` (or no
/// `env_prefix` is configured); `file` is `None` when it opts out with
/// `no_file` (or no file is configured).
///
/// # Errors
///
/// Returns [`LayeredError::Invalid`] if the winning layer supplies a value that
/// cannot be decoded into `T`, attributed to that layer.