Struct bpaf::params::ParseCommand
source · pub struct ParseCommand<T> { /* private fields */ }
Expand description
Implementations§
source§impl<P> ParseCommand<P>
impl<P> ParseCommand<P>
sourcepub fn help<M>(self, help: M) -> Selfwhere
M: Into<String>,
pub fn help<M>(self, help: M) -> Selfwhere
M: Into<String>,
Add a brief description to a command
bpaf
uses this description along with the command name
in help output so it shouldn’t exceed one or two lines. If help
isn’t specified
bpaf
falls back to descr
from the inner parser.
Combinatoric usage
fn inner() -> OptionParser<bool> {
short('i')
.help("Mysterious inner switch")
.switch()
.to_options()
.descr("performs an operation")
}
fn mysterious_parser() -> impl Parser<bool> {
command("mystery", inner())
.help("This command performs a mystery operation")
}
Derive usage
bpaf_derive
uses doc comments for inner parser, no specific options are available.
See descr
for more details
/// This command performs a mystery operation
#[derive(Debug, Clone, Bpaf)]
#[bpaf(command)]
struct Mystery {
#[bpaf(short)]
/// Mysterious inner switch
inner: bool,
}
Example
$ app --help
<skip>
Available commands:
mystery This command performs a mystery operation
Examples found in repository?
examples/enum_tuple.rs (line 27)
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
fn main() {
let bar = short('b')
.long("bar")
.help("some bar command")
.argument::<String>("BAR")
.optional();
let bar_cmd = construct!(Foo { bar })
.to_options()
.descr("This command will try to do foo given a bar argument");
let opt = command("foo", bar_cmd)
.help("command for doing foo")
.map(Command::Foo)
.to_options()
.run();
println!("{:#?}", opt);
}
More examples
examples/git.rs (line 51)
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
fn main() {
let dry_run = long("dry_run").switch();
let all = long("all").switch();
let repository = positional::<String>("SRC").fallback("origin".to_string());
let fetch = construct!(Opt::Fetch {
dry_run,
all,
repository
})
.to_options()
.descr("fetches branches from remote repository");
let fetch_cmd = command("fetch", fetch);
let interactive = short('i').switch();
let all = long("all").switch();
let files = positional::<PathBuf>("FILE").many();
let add = construct!(Opt::Add {
interactive,
all,
files
})
.to_options()
.descr("add files to the staging area");
let add_cmd = command("add", add).help("add files to the staging area");
let opt = construct!([fetch_cmd, add_cmd])
.to_options()
.descr("The stupid content tracker")
.run();
println!("{:?}", opt);
}
Trait Implementations§
source§impl<T> Parser<T> for ParseCommand<T>
impl<T> Parser<T> for ParseCommand<T>
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