pub fn fail<T>(msg: &'static str) -> ParseFail<T>
Expand description
Fail with a fixed error message
This parser produces T
of any type but instead of producing it when asked - it fails
with a custom error message. Can be useful for creating custom logic
§Combinatoric usage
fn must_agree() -> impl Parser<()> {
let a = long("accept").req_flag(());
let no_a = fail("You must accept the license agreement with --agree before proceeding");
construct!([a, no_a])
}
§Example
$ app
// exits with "You must accept the license agreement with --agree before proceeding"
$ app --agree
// succeeds