Arg

Struct Arg 

Source
pub struct Arg { /* private fields */ }
Expand description

Command-line argument specification

Defines a flag or option with optional short/long forms. Can be boolean (flag) or value-taking (option).

Implementations§

Source§

impl Arg

Source

pub fn new(name: impl Into<String>) -> Self

Source

pub fn long(self, long: impl Into<String>) -> Self

Source

pub fn short(self, short: char) -> Self

Source

pub fn help(self, help: impl Into<String>) -> Self

Source

pub fn takes_value(self, takes: bool) -> Self

Source

pub fn required(self, req: bool) -> Self

Source

pub fn default_value(self, value: impl Into<String>) -> Self

Set a default value for the argument

§Example
Arg::new("port")
    .takes_value(true)
    .default_value("8080");
Source

pub fn possible_values(self, values: &[&str]) -> Self

Restrict possible values

§Example
Arg::new("format")
    .takes_value(true)
    .possible_values(&["json", "yaml", "toml"]);
Source

pub fn validator(self, f: Validator) -> Self

Add a custom validator function

§Example
Arg::new("port")
    .takes_value(true)
    .validator(|v| {
        v.parse::<u16>()
            .map(|_| ())
            .map_err(|_| "must be a valid port number".to_string())
    });
Source

pub fn env(self, var: impl Into<String>) -> Self

Read value from specific environment variable

Source

pub fn hidden(self, hide: bool) -> Self

Hide this argument from help output

Source

pub fn conflicts_with(self, arg: impl Into<String>) -> Self

This argument conflicts with another

Source

pub fn requires(self, arg: impl Into<String>) -> Self

This argument requires another to be present

Auto Trait Implementations§

§

impl Freeze for Arg

§

impl RefUnwindSafe for Arg

§

impl Send for Arg

§

impl Sync for Arg

§

impl Unpin for Arg

§

impl UnwindSafe for Arg

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.