pub struct Argument {
pub name: String,
pub description: String,
pub required: bool,
pub default: Option<String>,
pub variadic: bool,
}Expand description
A positional argument accepted by a command.
Arguments are bound in declaration order when the parser consumes tokens after the command (and any subcommand) has been identified. Optional arguments may carry a default value that is substituted when the argument is absent.
Use Argument::builder to construct instances.
§Examples
let arg = Argument::builder("target")
.description("Deployment target environment")
.required()
.build()
.unwrap();
assert_eq!(arg.name, "target");
assert!(arg.required);
assert!(arg.default.is_none());Fields§
§name: StringThe canonical name of this argument, used as the key in crate::ParsedCommand::args.
description: StringHuman-readable description shown in help output.
required: boolWhether the parser returns an error when this argument is absent.
default: Option<String>Value substituted when the argument is not provided (optional arguments only).
variadic: boolWhether this argument consumes all remaining tokens (must be the last argument).
Implementations§
Source§impl Argument
impl Argument
Sourcepub fn builder(name: impl Into<String>) -> ArgumentBuilder
pub fn builder(name: impl Into<String>) -> ArgumentBuilder
Create a new ArgumentBuilder with the given name.
§Arguments
name— The argument name. Must be non-empty after trimming (enforced byArgumentBuilder::build).
§Examples
let arg = Argument::builder("file").build().unwrap();
assert_eq!(arg.name, "file");Trait Implementations§
Source§impl<'de> Deserialize<'de> for Argument
impl<'de> Deserialize<'de> for Argument
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Ord for Argument
impl Ord for Argument
Source§impl PartialOrd for Argument
impl PartialOrd for Argument
impl Eq for Argument
impl StructuralPartialEq for Argument
Auto Trait Implementations§
impl Freeze for Argument
impl RefUnwindSafe for Argument
impl Send for Argument
impl Sync for Argument
impl Unpin for Argument
impl UnsafeUnpin for Argument
impl UnwindSafe for Argument
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