pub struct SubCommandParser<'a, B: Display> { /* private fields */ }Expand description
The sub-command parser.
Implementations§
Source§impl<'a, B: FromStr + Display + PartialEq> SubCommandParser<'a, B>
impl<'a, B: FromStr + Display + PartialEq> SubCommandParser<'a, B>
Sourcepub fn command(
self,
variant: B,
setup_fn: impl FnOnce(SubCommand<'a>) -> SubCommand<'a>,
) -> Self
pub fn command( self, variant: B, setup_fn: impl FnOnce(SubCommand<'a>) -> SubCommand<'a>, ) -> Self
Setup a sub-command.
Sub-commands may be added arbitrarily, as long as the correspond to the branching type B.
If repeated for the same variant of B, only the final version will be created on the parser.
The order of sub-commands does not affect the command parser semantics.
§Example
use blarg::{CommandLineParser, Condition, Parameter, Scalar};
let mut value_a: u32 = 0;
let mut value_b: u32 = 0;
let mut sub_command: String = "".to_string();
let parser = CommandLineParser::new("program")
.branch(Condition::new(Scalar::new(&mut sub_command), "sub_command"))
.command("a".to_string(), |sub| sub.add(Parameter::argument(Scalar::new(&mut value_a), "value_a")))
.command("b".to_string(), |sub| {
sub.about("Description for the sub-command 'b'.")
.add(Parameter::argument(Scalar::new(&mut value_b), "value_b"))
})
.build();
parser.parse_tokens(vec!["a", "1"].as_slice()).unwrap();
assert_eq!(&sub_command, "a");
assert_eq!(value_a, 1);
assert_eq!(value_b, 0);Sourcepub fn build_parser(self) -> Result<GeneralParser<'a>, ConfigError>
pub fn build_parser(self) -> Result<GeneralParser<'a>, ConfigError>
Build the sub-command based command line parser as a Result. This finalizes the configuration and checks for errors (ex: a repeated parameter name).
Sourcepub fn build(self) -> GeneralParser<'a>
pub fn build(self) -> GeneralParser<'a>
Build the sub-command based command line parser.
This finalizes the configuration and checks for errors (ex: a repeated parameter name).
If an error is encountered, exits with error code 1 (via std::process::exit).
Auto Trait Implementations§
impl<'a, B> Freeze for SubCommandParser<'a, B>
impl<'a, B> !RefUnwindSafe for SubCommandParser<'a, B>
impl<'a, B> !Send for SubCommandParser<'a, B>
impl<'a, B> !Sync for SubCommandParser<'a, B>
impl<'a, B> Unpin for SubCommandParser<'a, B>where
B: Unpin,
impl<'a, B> !UnwindSafe for SubCommandParser<'a, B>
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