Struct BoolishValueParser

struct BoolishValueParser { ... }

Parse bool-like string values

See also:

Example

Usage:

# use clap_builder as clap;
let mut cmd = clap::Command::new("raw")
    .arg(
        clap::Arg::new("append")
            .value_parser(clap::builder::BoolishValueParser::new())
            .required(true)
    );

let m = cmd.try_get_matches_from_mut(["cmd", "true"]).unwrap();
let port: bool = *m.get_one("append")
    .expect("required");
assert_eq!(port, true);

Semantics:

# use clap_builder as clap;
# use std::ffi::OsStr;
# use clap::builder::TypedValueParser;
# let cmd = clap::Command::new("test");
# let arg = None;
let value_parser = clap::builder::BoolishValueParser::new();
assert!(value_parser.parse_ref(&cmd, arg, OsStr::new("random")).is_err());
assert!(value_parser.parse_ref(&cmd, arg, OsStr::new("")).is_err());
assert!(value_parser.parse_ref(&cmd, arg, OsStr::new("100")).is_err());
assert_eq!(value_parser.parse_ref(&cmd, arg, OsStr::new("true")).unwrap(), true);
assert_eq!(value_parser.parse_ref(&cmd, arg, OsStr::new("Yes")).unwrap(), true);
assert_eq!(value_parser.parse_ref(&cmd, arg, OsStr::new("oN")).unwrap(), true);
assert_eq!(value_parser.parse_ref(&cmd, arg, OsStr::new("1")).unwrap(), true);
assert_eq!(value_parser.parse_ref(&cmd, arg, OsStr::new("false")).unwrap(), false);
assert_eq!(value_parser.parse_ref(&cmd, arg, OsStr::new("No")).unwrap(), false);
assert_eq!(value_parser.parse_ref(&cmd, arg, OsStr::new("oFF")).unwrap(), false);
assert_eq!(value_parser.parse_ref(&cmd, arg, OsStr::new("0")).unwrap(), false);

Implementations

impl BoolishValueParser

fn new() -> Self

Parse bool-like string values

impl Clone for BoolishValueParser

fn clone(self: &Self) -> BoolishValueParser

impl Copy for BoolishValueParser

impl Debug for BoolishValueParser

fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result

impl Default for BoolishValueParser

fn default() -> Self

impl Freeze for BoolishValueParser

impl RefUnwindSafe for BoolishValueParser

impl Send for BoolishValueParser

impl Sync for BoolishValueParser

impl TypedValueParser for BoolishValueParser

fn parse_ref(self: &Self, cmd: &Command, arg: Option<&Arg>, value: &OsStr) -> Result<<Self as >::Value, Error>
fn possible_values(self: &Self) -> Option<Box<dyn Iterator<Item = PossibleValue> + '_>>

impl Unpin for BoolishValueParser

impl UnsafeUnpin for BoolishValueParser

impl UnwindSafe for BoolishValueParser

impl<I> IntoResettable for BoolishValueParser

fn into_resettable(self: Self) -> Resettable<ValueParser>

impl<T> Any for BoolishValueParser

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for BoolishValueParser

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for BoolishValueParser

fn borrow_mut(self: &mut Self) -> &mut T

impl<T> CloneToUninit for BoolishValueParser

unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)

impl<T> From for BoolishValueParser

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for BoolishValueParser

fn to_owned(self: &Self) -> T
fn clone_into(self: &Self, target: &mut T)

impl<T, U> Into for BoolishValueParser

fn into(self: Self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom for BoolishValueParser

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto for BoolishValueParser

fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>