Struct bpaf::params::ParseArgument
source · pub struct ParseArgument<T> { /* private fields */ }
Expand description
Parser for a named argument, created with argument
.
Implementations§
source§impl<T> ParseArgument<T>
impl<T> ParseArgument<T>
sourcepub fn adjacent(self) -> Self
pub fn adjacent(self) -> Self
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§
source§impl<T: Clone> Clone for ParseArgument<T>
impl<T: Clone> Clone for ParseArgument<T>
source§fn clone(&self) -> ParseArgument<T>
fn clone(&self) -> ParseArgument<T>
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl<T> Parser<T> for ParseArgument<T>where
T: FromStr + 'static,
<T as FromStr>::Err: Display,
impl<T> Parser<T> for ParseArgument<T>where
T: FromStr + 'static,
<T as FromStr>::Err: Display,
source§fn some(self, message: &'static str) -> ParseSome<Self>where
Self: Sized + Parser<T>,
fn some(self, message: &'static str) -> ParseSome<Self>where
Self: Sized + Parser<T>,
Consume one or more items from a command line Read more
source§fn optional(self) -> ParseOptional<Self>where
Self: Sized + Parser<T>,
fn optional(self) -> ParseOptional<Self>where
Self: Sized + Parser<T>,
Turn a required argument into optional one Read more
source§fn parse<F, R, E>(self, f: F) -> ParseWith<T, Self, F, E, R>where
Self: Sized + Parser<T>,
F: Fn(T) -> Result<R, E>,
E: ToString,
fn parse<F, R, E>(self, f: F) -> ParseWith<T, Self, F, E, R>where
Self: Sized + Parser<T>,
F: Fn(T) -> Result<R, E>,
E: ToString,
Apply a failing transformation to a contained value Read more
source§fn map<F, R>(self, map: F) -> ParseMap<T, Self, F, R>where
Self: Sized + Parser<T>,
F: Fn(T) -> R + 'static,
fn map<F, R>(self, map: F) -> ParseMap<T, Self, F, R>where
Self: Sized + Parser<T>,
F: Fn(T) -> R + 'static,
Apply a pure transformation to a contained value Read more
source§fn guard<F>(self, check: F, message: &'static str) -> ParseGuard<Self, F>where
Self: Sized + Parser<T>,
F: Fn(&T) -> bool,
fn guard<F>(self, check: F, message: &'static str) -> ParseGuard<Self, F>where
Self: Sized + Parser<T>,
F: Fn(&T) -> bool,
Validate or fail with a message Read more
source§fn fallback(self, value: T) -> ParseFallback<Self, T>where
Self: Sized + Parser<T>,
fn fallback(self, value: T) -> ParseFallback<Self, T>where
Self: Sized + Parser<T>,
Use this value as default if value isn’t present on a command line Read more
source§fn fallback_with<F, E>(self, fallback: F) -> ParseFallbackWith<T, Self, F, E>where
Self: Sized + Parser<T>,
F: Fn() -> Result<T, E>,
E: ToString,
fn fallback_with<F, E>(self, fallback: F) -> ParseFallbackWith<T, Self, F, E>where
Self: Sized + Parser<T>,
F: Fn() -> Result<T, E>,
E: ToString,
Use value produced by this function as default if value isn’t present Read more
source§fn hide(self) -> ParseHide<Self>where
Self: Sized + Parser<T>,
fn hide(self) -> ParseHide<Self>where
Self: Sized + Parser<T>,
Ignore this parser during any sort of help generation Read more
source§fn hide_usage(self) -> ParseHideUsage<Self>where
Self: Sized + Parser<T>,
fn hide_usage(self) -> ParseHideUsage<Self>where
Self: Sized + Parser<T>,
Ignore this parser when generating usage line Read more
source§fn group_help(self, message: &'static str) -> ParseGroupHelp<Self>where
Self: Sized + Parser<T>,
fn group_help(self, message: &'static str) -> ParseGroupHelp<Self>where
Self: Sized + Parser<T>,
Attach help message to a complex parser Read more
source§fn complete<M, F>(self, op: F) -> ParseComp<Self, F>where
M: Into<String>,
F: Fn(&T) -> Vec<(M, Option<M>)>,
Self: Sized + Parser<T>,
fn complete<M, F>(self, op: F) -> ParseComp<Self, F>where
M: Into<String>,
F: Fn(&T) -> Vec<(M, Option<M>)>,
Self: Sized + Parser<T>,
Dynamic shell completion Read more
source§fn complete_shell(self, op: ShellComp) -> ParseCompShell<Self>where
Self: Sized + Parser<T>,
fn complete_shell(self, op: ShellComp) -> ParseCompShell<Self>where
Self: Sized + Parser<T>,
Static shell completion Read more
source§fn complete_style(self, style: CompleteDecor) -> ParseCompStyle<Self>where
Self: Sized + Parser<T>,
fn complete_style(self, style: CompleteDecor) -> ParseCompStyle<Self>where
Self: Sized + Parser<T>,
Add extra annotations to completion information Read more
source§fn adjacent(self) -> ParseAdjacent<Self>where
Self: Sized + Parser<T>,
fn adjacent(self) -> ParseAdjacent<Self>where
Self: Sized + Parser<T>,
Automagically restrict the inner parser scope to accept adjacent values only Read more
source§fn anywhere(self) -> ParseAnywhere<Self>where
Self: Sized + Parser<T>,
fn anywhere(self) -> ParseAnywhere<Self>where
Self: Sized + Parser<T>,
Parse anywhere Read more