Skip to main content

CliLayer

Struct CliLayer 

Source
pub struct CliLayer { /* private fields */ }
Expand description

Settings given on the command line.

Implementations§

Source§

impl CliLayer

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn is_empty(&self) -> bool

Whether a flag was given for anything at all.

A CLI with no settings on its command line can leave this layer out of the plan rather than adding an empty one, though adding one changes nothing.

Trait Implementations§

Source§

impl Layer for CliLayer

Source§

fn source(&self) -> SourceKind

Which kind of place this reads. Used by the scope check and reported by explain.
Source§

fn load(&self, ctx: &LayerCtx) -> Result<LayerOutput, LayerError>

Everything this layer has to say, in one pass.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.