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 help<M>(self, help: M) -> Self
pub fn help<M>(self, help: M) -> Self
Add a help message to an argument
See NamedArg::help
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 example
#[derive(Debug, Clone)]
pub struct Options {
package: String,
}
fn package() -> impl Parser<String> {
long("package")
.short('p')
.help("Package to use")
.argument("SPEC")
.adjacent()
}
pub fn options() -> OptionParser<Options> {
construct!(Options { package() }).to_options()
}
fn main() {
println!("{:?}", options().run())
}
Derive example
#[derive(Debug, Clone, Bpaf)]
#[bpaf(options)]
pub struct Options {
#[bpaf(short, long, argument("SPEC"), adjacent)]
/// Package to use
package: String,
}
fn main() {
println!("{:?}", options().run())
}
Output
$ app --help
Usage: app -p=SPEC
Available options:
- -p, --package=SPEC
- Package to use
- -h, --help
- Prints help information
As with regular argument
its adjacent
variant is required by default
$ app
Error: expected --package=SPEC, pass --help for usage information
Error: expected --package=SPEC, pass --help for usage information
But unlike regular variant adjacent
requires name and value to be separated by =
only
$ app -p=htb
Options { package: "htb" }
Options { package: "htb" }
$ app --package=bpaf
Options { package: "bpaf" }
Options { package: "bpaf" }
Separating them by space results in parse failure
$ app --package htb
Error: expected --package=SPEC, got --package. Pass --help for usage information
Error: expected --package=SPEC, got --package. Pass --help for usage information
$ app -p htb
Error: expected --package=SPEC, got -p. Pass --help for usage information
Error: expected --package=SPEC, got -p. Pass --help for usage information
$ app --package
Error: expected --package=SPEC, got --package. Pass --help for usage information
Error: expected --package=SPEC, got --package. Pass --help for usage information
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>
impl<T> Parser<T> for ParseArgument<T>
Source§fn collect<C>(self) -> ParseCollect<Self, C, T>where
C: FromIterator<T>,
Self: Sized,
fn collect<C>(self) -> ParseCollect<Self, C, T>where
C: FromIterator<T>,
Self: Sized,
Transform parser into a collection parser Read more
Source§fn optional(self) -> ParseOptional<Self>
fn optional(self) -> ParseOptional<Self>
Turn a required argument into an optional one Read more
Source§fn count(self) -> ParseCount<Self, T>
fn count(self) -> ParseCount<Self, T>
Count how many times the inner parser succeeds, and return that number. Read more
Source§fn last(self) -> ParseLast<Self>
fn last(self) -> ParseLast<Self>
Apply the inner parser as many times as it succeeds, return the last value Read more
Source§fn parse<F, R, E>(self, f: F) -> ParseWith<T, Self, F, E, R>
fn parse<F, R, E>(self, f: F) -> ParseWith<T, Self, F, E, R>
Apply a failing transformation to a contained value Read more
Source§fn map<F, R>(self, map: F) -> ParseMap<T, Self, F, R>
fn map<F, R>(self, map: F) -> ParseMap<T, Self, F, R>
Apply a pure transformation to a contained value Read more
Source§fn guard<F>(self, check: F, message: &'static str) -> ParseGuard<Self, F>
fn guard<F>(self, check: F, message: &'static str) -> ParseGuard<Self, F>
Validate or fail with a message Read more
Source§fn fallback(self, value: T) -> ParseFallback<Self, T>
fn fallback(self, value: T) -> ParseFallback<Self, T>
Use this value as default if the value isn’t present on a command line Read more
Source§fn fallback_with<F, E>(self, fallback: F) -> ParseFallbackWith<T, Self, F, E>
fn fallback_with<F, E>(self, fallback: F) -> ParseFallbackWith<T, Self, F, E>
Use value produced by this function as default if the value isn’t present Read more
Source§fn hide(self) -> ParseHide<Self>
fn hide(self) -> ParseHide<Self>
Ignore this parser during any sort of help generation Read more
Source§fn hide_usage(self) -> ParseUsage<Self>
fn hide_usage(self) -> ParseUsage<Self>
Ignore this parser when generating a usage line Read more
Source§fn custom_usage<M>(self, usage: M) -> ParseUsage<Self>
fn custom_usage<M>(self, usage: M) -> ParseUsage<Self>
Customize how this parser looks like in the usage line Read more
Source§fn group_help<M: Into<Doc>>(self, message: M) -> ParseGroupHelp<Self>
fn group_help<M: Into<Doc>>(self, message: M) -> ParseGroupHelp<Self>
Attach a help message to a complex parser Read more
Source§fn with_group_help<F>(self, f: F) -> ParseWithGroupHelp<Self, F>
fn with_group_help<F>(self, f: F) -> ParseWithGroupHelp<Self, F>
Source§fn complete<M, F>(self, op: F) -> ParseComp<Self, F>
fn complete<M, F>(self, op: F) -> ParseComp<Self, F>
Available on crate feature
autocomplete
only.Dynamic shell completion Read more
Source§fn complete_shell(self, op: ShellComp) -> ParseCompShell<Self>
fn complete_shell(self, op: ShellComp) -> ParseCompShell<Self>
Available on crate feature
autocomplete
only.Static shell completion Read more
Source§fn to_options(self) -> OptionParser<T>
fn to_options(self) -> OptionParser<T>
Auto Trait Implementations§
impl<T> Freeze for ParseArgument<T>
impl<T> RefUnwindSafe for ParseArgument<T>where
T: RefUnwindSafe,
impl<T> Send for ParseArgument<T>where
T: Send,
impl<T> Sync for ParseArgument<T>where
T: Sync,
impl<T> Unpin for ParseArgument<T>where
T: Unpin,
impl<T> UnwindSafe for ParseArgument<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more