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
impl Arg
pub fn new(name: impl Into<String>) -> Self
pub fn long(self, long: impl Into<String>) -> Self
pub fn short(self, short: char) -> Self
pub fn help(self, help: impl Into<String>) -> Self
pub fn takes_value(self, takes: bool) -> Self
pub fn required(self, req: bool) -> Self
Sourcepub fn default_value(self, value: impl Into<String>) -> Self
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");Sourcepub fn possible_values(self, values: &[&str]) -> Self
pub fn possible_values(self, values: &[&str]) -> Self
Restrict possible values
§Example
Arg::new("format")
.takes_value(true)
.possible_values(&["json", "yaml", "toml"]);Sourcepub fn validator(self, f: Validator) -> Self
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())
});Hide this argument from help output
Sourcepub fn conflicts_with(self, arg: impl Into<String>) -> Self
pub fn conflicts_with(self, arg: impl Into<String>) -> Self
This argument conflicts with another
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more