Struct FalseyValueParser

#[non_exhaustive]
pub struct FalseyValueParser {}

Parse false-like string values, everything else is true

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::FalseyValueParser::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::FalseyValueParser::new();
assert_eq!(value_parser.parse_ref(&cmd, arg, OsStr::new("random")).unwrap(), true);
assert_eq!(value_parser.parse_ref(&cmd, arg, OsStr::new("100")).unwrap(), true);
assert_eq!(value_parser.parse_ref(&cmd, arg, OsStr::new("")).unwrap(), false);
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 FalseyValueParser

fn new() -> Self

Parse false-like string values, everything else is true

Trait Implementations

impl Clone for FalseyValueParser

fn clone(&self) -> FalseyValueParser

impl Copy for FalseyValueParser

impl Debug for FalseyValueParser

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

impl Default for FalseyValueParser

fn default() -> Self

impl TypedValueParser for FalseyValueParser

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

Auto Trait Implementations

impl Freeze for FalseyValueParser

impl RefUnwindSafe for FalseyValueParser

impl Send for FalseyValueParser

impl Sync for FalseyValueParser

impl Unpin for FalseyValueParser

impl UnsafeUnpin for FalseyValueParser

impl UnwindSafe for FalseyValueParser

Blanket Implementations

impl<I> IntoResettable<ValueParser> for FalseyValueParser where I: Into<ValueParser>,

fn into_resettable(self) -> Resettable<ValueParser>

impl<T> Any for FalseyValueParser where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for FalseyValueParser where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for FalseyValueParser where T: ?Sized,

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

impl<T> CloneToUninit for FalseyValueParser where T: Clone,

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

impl<T> From<T> for FalseyValueParser

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for FalseyValueParser where T: Clone,

type Owned = T;
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)

impl<T, U> Into<U> for FalseyValueParser where U: From<T>,

fn into(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<U> for FalseyValueParser where U: Into<T>,

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

impl<T, U> TryInto<U> for FalseyValueParser where U: TryFrom<T>,

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