Struct bpaf::params::ParseArgument

source ·
pub struct ParseArgument<T> { /* private fields */ }
Expand description

Parser for a named argument, created with argument.

Implementations§

Restrict parsed arguments to have both flag and a value in the same word:

In other words adjacent restricted ParseArgument would accept --flag=value or -fbar but not --flag value. Note, this is different from adjacent, just plays a similar role.

Should allow to parse some of the more unusual things

Combinatoric usage
#[derive(Debug, Clone)]
pub struct Options {
    banana: bool,
    switch: bool,
}

// accepts `-banana`, note a single dash
fn banana() -> impl Parser<bool> {
    short('b')
        .argument::<std::ffi::OsString>("anana")
        .adjacent()
        .guard(|b| b == "anana", "not anana")
        .optional()
        .catch()
        .map(|b| b.is_some())
}

pub fn options() -> OptionParser<Options> {
    let switch = short('s').switch();
    // banana() is just a syntax construct! allows, not magic
    construct!(Options { banana(), switch }).to_options()
}
Examples

other than looking strange banana() should behave like a regular flag parser: banana - yes

% app -banana -s
Options { banana: true, switch: true }

banana - no

% app -s
Options { banana: false, switch: true }

this is also accepted but close enough I think

% app -b=anana
Options { banana: true, switch: false }

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Consume zero or more items from a command line and collect them into Vec Read more
Consume one or more items from a command line Read more
Turn a required argument into optional one Read more
Apply a failing transformation to a contained value Read more
Apply a pure transformation to a contained value Read more
Validate or fail with a message Read more
Use this value as default if value isn’t present on a command line Read more
Use value produced by this function as default if value isn’t present Read more
Ignore this parser during any sort of help generation Read more
Ignore this parser when generating usage line Read more
Attach help message to a complex parser Read more
Dynamic shell completion Read more
Static shell completion Read more
Add extra annotations to completion information Read more
Automagically restrict the inner parser scope to accept adjacent values only Read more
Parse anywhere Read more
Transform Parser into OptionParser to attach metadata and run Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.