pub struct CliLayer { /* private fields */ }Expand description
Settings given on the command line.
Implementations§
Source§impl CliLayer
impl CliLayer
Sourcepub fn new(
given: impl IntoIterator<Item = (impl Into<String>, impl Into<String>)>,
) -> Self
pub fn new( given: impl IntoIterator<Item = (impl Into<String>, impl Into<String>)>, ) -> Self
The settings a flag was given for, as text.
Only what was given: a flag left off the command line is not an entry here, because the command line outranks every other layer and an entry it did not earn would silently beat a file the user did write.
Sourcepub fn with(self, key: impl Into<String>, value: impl Into<String>) -> Self
pub fn with(self, key: impl Into<String>, value: impl Into<String>) -> Self
A setting given as text, added to what this layer already has.
Chained rather than collected, so a CLI can build the layer with one call per flag it has and
leave out the ones it has not — which is the shape a generated to_settings_layer wants.
Sourcepub fn with_value(self, key: impl Into<String>, value: Value) -> Self
pub fn with_value(self, key: impl Into<String>, value: Value) -> Self
A setting given as a value that already has a shape.
A switch is a bool, a --verbose count is a number, a repeated flag is a list: a caller
holding those has no reason to render them to text for this to read them back.
Sourcepub fn with_unrepresentable(self, key: impl Into<String>) -> Self
pub fn with_unrepresentable(self, key: impl Into<String>) -> Self
A setting whose flag was given a value that cannot be one.
An argument is bytes and a setting is text — every layer below this one reads a file or a
variable that had to be UTF-8 to exist. On Unix a path need not be, so --exclude can be
handed something the resolution has nowhere to put. Rendering it lossily would set the
setting to a value nobody typed, and one that no longer names the file it came from, while
the CLI’s own field still holds the real bytes: one flag, two answers. This says so instead,
and the setting keeps whatever the layers below it gave.
Trait Implementations§
Source§impl Layer for CliLayer
impl Layer for CliLayer
Source§fn source(&self) -> SourceKind
fn source(&self) -> SourceKind
explain.