pub struct Argument {
pub config: ParameterConfig,
pub default_value: Option<String>,
/* private fields */
}Expand description
A positional command-line argument.
Arguments are positional parameters that appear without dashes. Unlike options, they are required by default and have a single name (no aliases).
§Key Differences from Options
- Arguments are positional (no
--prefix) - Required by default (unless a default is provided)
- Single name only (no short/long aliases)
- Name is displayed in uppercase in help text
§Example
use click::argument::Argument;
use click::parameter::Parameter;
// Required argument
let filename = Argument::new("filename").build();
assert!(filename.required());
// Optional argument with default
let output = Argument::new("output")
.default("out.txt")
.build();
assert!(!output.required());Fields§
§config: ParameterConfigParameter configuration.
default_value: Option<String>The default value (if any).
Implementations§
Source§impl Argument
impl Argument
Sourcepub fn new(name: &str) -> ArgumentBuilder
pub fn new(name: &str) -> ArgumentBuilder
Create a new argument builder with the given name.
§Example
use click::argument::Argument;
let arg = Argument::builder("filename")
.help("The file to process")
.required(true)
.build();Sourcepub fn builder(name: &str) -> ArgumentBuilder
pub fn builder(name: &str) -> ArgumentBuilder
Alias for new() - create a new argument builder.
Sourcepub fn type_converter(&self) -> &dyn AnyTypeConverter
pub fn type_converter(&self) -> &dyn AnyTypeConverter
Get the type converter for this argument.
Sourcepub fn convert_any(
&self,
value: &str,
) -> Result<Box<dyn Any + Send + Sync>, String>
pub fn convert_any( &self, value: &str, ) -> Result<Box<dyn Any + Send + Sync>, String>
Convert a string value using this argument’s type converter. Returns the converted value as a boxed Any type.
Sourcepub fn convert(&self, value: &str) -> Result<String, String>
pub fn convert(&self, value: &str) -> Result<String, String>
Convert a string value using this argument’s type converter.
This is a convenience method that attempts to downcast to String.
For non-String types, use convert_any instead.
Sourcepub fn get_completions(
&self,
ctx: &Context,
incomplete: &str,
) -> Vec<CompletionItem>
pub fn get_completions( &self, ctx: &Context, incomplete: &str, ) -> Vec<CompletionItem>
Get shell completions for this argument.
If a custom shell_complete callback is set, it will be used. Otherwise, completions from the type converter are returned.
Sourcepub fn has_shell_complete_callback(&self) -> bool
pub fn has_shell_complete_callback(&self) -> bool
Check if this argument has a custom shell_complete callback.
Sourcepub fn default_value(&self) -> Option<&str>
pub fn default_value(&self) -> Option<&str>
Get the default value for this argument.
Sourcepub fn make_metavar(&self) -> String
pub fn make_metavar(&self) -> String
Generate the metavar for this argument (used in help text).
The metavar is formatted according to Click’s conventions:
- Custom metavar if set, otherwise uppercase name
- Wrapped in
[]if optional - Suffixed with
...if variadic or multiple - Suffixed with
!if deprecated
Note: Unlike options, arguments use their name (uppercase) by default, not the type’s metavar. This matches Python Click’s behavior.
Trait Implementations§
Source§impl Parameter for Argument
impl Parameter for Argument
Source§fn human_readable_name(&self) -> String
fn human_readable_name(&self) -> String
Source§fn is_eager(&self) -> bool
fn is_eager(&self) -> bool
Source§fn expose_value(&self) -> bool
fn expose_value(&self) -> bool
ctx.params. Read more