pub struct ArgumentBuilder { /* private fields */ }Expand description
Consuming builder for Argument.
Obtain via Argument::builder. Call ArgumentBuilder::build when done.
§Examples
let arg = Argument::builder("format")
.description("Output format")
.default_value("text")
.build()
.unwrap();
assert_eq!(arg.default.as_deref(), Some("text"));
assert!(!arg.required);Implementations§
Source§impl ArgumentBuilder
impl ArgumentBuilder
Sourcepub fn description(self, d: impl Into<String>) -> Self
pub fn description(self, d: impl Into<String>) -> Self
Set the human-readable description for this argument.
Sourcepub fn required(self) -> Self
pub fn required(self) -> Self
Mark this argument as required.
The parser will return crate::ParseError::MissingArgument if the
argument is absent from the invocation.
Sourcepub fn default_value(self, d: impl Into<String>) -> Self
pub fn default_value(self, d: impl Into<String>) -> Self
Set the default value used when this argument is not provided.
A default value is only meaningful for optional (non-required) arguments. If the argument is required and has a default, the default is still stored but the parser will still require the argument to be supplied.
Sourcepub fn variadic(self) -> Self
pub fn variadic(self) -> Self
Mark this argument as variadic (consumes all remaining tokens).
A variadic argument must be the last argument defined on the command.
crate::CommandBuilder::build enforces this constraint and returns
crate::BuildError::VariadicNotLast if a variadic argument is
followed by another argument.
Sourcepub fn build(self) -> Result<Argument, BuildError>
pub fn build(self) -> Result<Argument, BuildError>
Consume the builder and return an Argument.
§Errors
Returns BuildError::EmptyCanonical if the argument name is empty or
consists entirely of whitespace.
§Examples
assert!(Argument::builder("env").build().is_ok());
assert_eq!(Argument::builder("").build().unwrap_err(), BuildError::EmptyCanonical);