Module bpaf::_documentation::_1_tutorials::_1_combinatoric_api::_0_simple_parser::_2_positional
source · Expand description
Positional item parser
And the last simple option type is a parser for positional items. Since there’s no name you use
the positional function directly. Similar to NamedArg::argument this method takes
a metavariable name and a type parameter in some form. You can also attach the help message
thanks to ParsePositional::help
Full example:
use bpaf::*;
pub fn options() -> OptionParser<String> {
let simple = positional("URL").help("Url to open");
simple.to_options()
}
fn main() {
println!("{:?}", options().run())
}Output
Same as with argument by default there’s no fallback so with no arguments parser fails
$ app
Error: expected URL, pass --help for usage information
Error: expected URL, pass --help for usage information
Other than that any name that does not start with a dash or explicitly converted to positional parameter gets parsed:
$ app https://lemmyrs.org
"https://lemmyrs.org"
"https://lemmyrs.org"
$ app "strange url"
"strange url"
"strange url"
$ app -- --can-start-with-dash-too
"--can-start-with-dash-too"
"--can-start-with-dash-too"
And as usual there’s help message
$ app --help
Usage: app URL
Available positional items:
- URL
- Url to open
Available options:
- -h, --help
- Prints help information