Skip to main content

SpecArg

Struct SpecArg 

Source
#[non_exhaustive]
pub struct SpecArg {
Show 39 fields pub name: String, pub value_names: Vec<String>, pub usage: String, pub help: Option<String>, pub help_long: Option<String>, pub help_md: Option<String>, pub help_first_line: Option<String>, pub required: bool, pub double_dash: SpecDoubleDashChoices, pub var: bool, pub var_min: Option<usize>, pub var_max: Option<usize>, pub delimiter: Option<char>, pub allow_negative_numbers: bool, pub value_terminator: Option<String>, pub hide: bool, pub hide_default_value: bool, pub hide_env: bool, pub hide_env_values: bool, pub hide_possible_values: bool, pub hide_short_help: bool, pub hide_long_help: bool, pub conflicts: Vec<String>, pub requires: Vec<String>, pub required_if: Vec<String>, pub required_if_eq: Vec<SpecRequiredIfEq>, pub required_if_eq_all: Vec<SpecRequiredIfEq>, pub required_unless: Vec<String>, pub required_unless_all: Vec<String>, pub default: Vec<String>, pub choices: Option<SpecChoices>, pub validate: Option<String>, pub validate_error: Option<String>, pub effect: Option<SpecCommandEffect>, pub env: Option<String>, pub env_fallback: Vec<String>, pub deprecated_env: Vec<String>, pub help_heading: Option<String>, pub display_order: Option<usize>,
}
Expand description

A positional argument specification.

Arguments are positional values passed to a command without a flag prefix. They can be required or optional, and can accept multiple values (variadic).

§Example

use usage::SpecArg;

let arg = SpecArg::builder()
    .name("file")
    .required(true)
    .help("Input file to process")
    .build();

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§name: String

Name of the argument (used in help text)

§value_names: Vec<String>

Ordered placeholders for a fixed-arity value, such as START and END. Empty means the argument’s name is the sole placeholder.

§usage: String

Generated usage string (e.g., “” or “file”)

§help: Option<String>

Short help text shown in command listings

§help_long: Option<String>

Extended help text shown with –help

§help_md: Option<String>

Markdown-formatted help text

§help_first_line: Option<String>

First line of help text (auto-generated)

§required: bool

Whether this argument must be provided

§double_dash: SpecDoubleDashChoices

How to handle the “–” separator

§var: bool

Whether this argument accepts multiple values

§var_min: Option<usize>

Minimum number of values for variadic arguments

§var_max: Option<usize>

Maximum number of values for variadic arguments

§delimiter: Option<char>

The character a single word is split on to produce several values.

--tags a,b,c as three values rather than one, which is clap’s value_delimiter. Only meaningful where several values can land, so it goes with SpecArg::var; declaring it anywhere else is refused rather than silently dropping everything after the first separator.

§allow_negative_numbers: bool

Accept negative numeric tokens without accepting arbitrary dash-prefixed words.

§value_terminator: Option<String>

End this variadic argument when this token is seen, without binding it.

§hide: bool

Whether to hide this argument from help output

§hide_default_value: bool

Hide the default annotation while keeping the default behavior.

§hide_env: bool

Hide the environment annotation entirely.

§hide_env_values: bool

Hide an environment value while retaining its variable name.

§hide_possible_values: bool

Hide possible values from help without changing validation.

§hide_short_help: bool

Hide this argument only from short help.

§hide_long_help: bool

Hide this argument only from long help.

§conflicts: Vec<String>

Arguments and flags that cannot be given alongside this positional.

A bare selector names another positional by name; flag selectors keep their --long or -s spelling.

§requires: Vec<String>

Arguments that must also be present when this positional is present.

§required_if: Vec<String>

Presence conditions, any one of which makes this positional required.

§required_if_eq: Vec<SpecRequiredIfEq>

Value conditions, any one of which makes this positional required.

§required_if_eq_all: Vec<SpecRequiredIfEq>

Value conditions which must all match to make this positional required.

§required_unless: Vec<String>

Any present selector waives this positional’s requirement.

§required_unless_all: Vec<String>

Only the presence of every selector waives this positional’s requirement.

§default: Vec<String>

Default value(s) if the argument is not provided

§choices: Option<SpecChoices>

Valid choices for this argument

§validate: Option<String>

A portable expr expression that must return true for each raw value.

§validate_error: Option<String>

Message reported when SpecArg::validate returns false.

§effect: Option<SpecCommandEffect>

Raises the effect of the command when this argument is supplied. See crate::spec::effect::SpecCommandEffect; never lowers it.

§env: Option<String>

Environment variable that can provide this argument’s value

§env_fallback: Vec<String>

Additional environment variables, consulted in declaration order.

§deprecated_env: Vec<String>

Deprecated environment aliases, consulted after ordinary fallbacks.

§help_heading: Option<String>

Heading this argument is listed under in help output. Presentational only, like the flag field of the same name.

§display_order: Option<usize>

Explicit placement within its help section.

Implementations§

Source§

impl SpecArg

Source

pub fn builder() -> SpecArgBuilder

Create a new builder for SpecArg

Source

pub fn env_names(&self) -> impl Iterator<Item = &str>

Environment variable names in the order used to fill this argument.

Source§

impl SpecArg

Source

pub fn usage(&self) -> String

Trait Implementations§

Source§

impl Clone for SpecArg

Source§

fn clone(&self) -> SpecArg

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SpecArg

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SpecArg

Source§

fn default() -> SpecArg

Returns the “default value” for a type. Read more
Source§

impl Display for SpecArg

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for SpecArg

Source§

impl From<&SpecArg> for KdlNode

Source§

fn from(arg: &SpecArg) -> Self

Converts to this type from the input type.
Source§

impl From<&str> for SpecArg

Source§

fn from(input: &str) -> Self

Converts to this type from the input type.
Source§

impl FromStr for SpecArg

Source§

type Err = UsageErr

The associated error which can be returned from parsing.
Source§

fn from_str(input: &str) -> Result<Self, UsageErr>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for SpecArg

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for SpecArg

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for SpecArg

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.