Yet Another Callback-orientated Command line pArSer is ... well, yet another command line parser.
Indeed, there are so many command line parser written in Rust out there... But would I have written this one if it is like all the other? Let me convince you: Why should you choose this one?
```Rust
extern crate yaccas;
use yaccas::arguments::{Command, Flag, Value}; use yaccas::parser::{Parser, FreeArgumentSupport, Result};
fn main() { let mut willbetrueifflagisset = false; let mut willbe42aseverytime = 0u32;
{ // It's time for some magic ...
// There a three types of arguments
let flag = Flag::default();
let value = Value::new::<u32>();
let command = Command::new(|| Some("A fancy name for abort"));
// Registers the arguments to a parser.
// All callbacks will only be executed if parsing was successful!
let mut parser = Parser::default();
parser.register(&["option", "o1", "o2"], flag, | flag | {
// Flags are options which may occur 0 - x times.
will_be_true_if_flag_is_set = flag.is_activated();
});
parser.register(&["value", "v"], value, | value | {
// Values are command line argument-value pairs of a specific type.
will_be_42_as_everytime = value.get_value::<u32>().expect("The answer for everything is 42!");
});
parser.register(&["abort"], command, | _command | {
// Commands may or may not abort the execution of parsing, i.e. for "help".
// This callback is a fallback: It is only called if the process was not aborted!
});
match parser.parse(default_scanner!()) {
Result::Success(free_arguments) => { /* ... */ },
Result::Aborted("A fancy name for abort") => { /* ... */ },
_ => { /* ... */ }
}
}
// Do something with "will_be_true_if_flag_is_set" or "will_be_42_as_everytime" here ...
} ```
Christopher Gundler (c.gundler@mail.de)
Licensed under either of * Apache License, Version 2.0, (http://www.apache.org/licenses/LICENSE-2.0) * MIT license (http://opensource.org/licenses/MIT)
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.