Skip to main content

ArgSpec

Struct ArgSpec 

Source
pub struct ArgSpec {
Show 18 fields pub id: String, pub long: Option<String>, pub short: Option<char>, pub short_aliases: Vec<char>, pub aliases: Vec<String>, pub value_name: Option<String>, pub value: ValueHint, pub help: String, pub long_help: Option<String>, pub default: Option<String>, pub env: Option<String>, pub config_key: Option<String>, pub required: bool, pub multiple: bool, pub hidden: bool, pub heading: Option<String>, pub positional: bool, pub global: bool,
}
Expand description

An option, flag or positional argument.

use rich_ext::cli_doc::{ArgSpec, ValueHint};

let color = ArgSpec::option("color")
    .value_name("WHEN")
    .choices(["auto", "always", "never"])
    .default_value("auto")
    .env("RICH_COLOR")
    .help("When to use colour");
assert_eq!(color.names(), "--color <WHEN>");
assert!(matches!(color.value, ValueHint::Choices(ref c) if c.len() == 3));

Fields§

§id: String

A stable identifier; also the default value name.

§long: Option<String>

The long name, without dashes.

§short: Option<char>§short_aliases: Vec<char>

Extra short names, without the dash (-J beside -j).

§aliases: Vec<String>

Extra long names, without dashes.

§value_name: Option<String>

The metavar shown as <VALUE>. None makes the argument a flag.

§value: ValueHint§help: String§long_help: Option<String>

Help for --help (long) output; help is used when absent.

§default: Option<String>§env: Option<String>

The environment variable that sets this argument.

§config_key: Option<String>

The config file key that sets this argument.

§required: bool§multiple: bool

Whether the argument may be given more than once (or takes a list).

§hidden: bool

Hidden arguments are left out of help, docs and completions.

§heading: Option<String>

The help group title; None means “Options” (or “Arguments” for a positional).

§positional: bool§global: bool

A global option applies to every subcommand below the command that declares it, so completions offer it there too (clap’s Arg::global).

Implementations§

Source§

impl ArgSpec

Source

pub fn new(id: impl Into<String>) -> Self

A bare argument with only an id; set the rest with the builders.

Source

pub fn flag(long: impl Into<String>) -> Self

A --long flag that takes no value.

Source

pub fn option(long: impl Into<String>) -> Self

A --long <LONG> option taking any value.

Source

pub fn positional(name: impl Into<String>) -> Self

A positional argument shown as [NAME], or <NAME> when required.

Source

pub fn long(self, long: impl Into<String>) -> Self

Source

pub fn short(self, short: char) -> Self

Source

pub fn alias(self, alias: impl Into<String>) -> Self

Source

pub fn short_alias(self, short: char) -> Self

Another short name, listed after short.

Source

pub fn value_name(self, name: impl Into<String>) -> Self

Set the metavar; this also makes a flag take a value.

Source

pub fn value(self, hint: ValueHint) -> Self

Set the value hint; a non-None hint makes a flag take a value.

Source

pub fn choices<C: Into<Choice>>( self, choices: impl IntoIterator<Item = C>, ) -> Self

Restrict the value to choices.

Source

pub fn choice(self, value: impl Into<String>, help: impl Into<String>) -> Self

Add one allowed value with help.

Source

pub fn help(self, help: impl Into<String>) -> Self

Source

pub fn long_help(self, help: impl Into<String>) -> Self

Source

pub fn default_value(self, value: impl Into<String>) -> Self

Source

pub fn env(self, name: impl Into<String>) -> Self

Source

pub fn config_key(self, key: impl Into<String>) -> Self

Source

pub fn required(self, required: bool) -> Self

Source

pub fn multiple(self, multiple: bool) -> Self

Source

pub fn hidden(self, hidden: bool) -> Self

Source

pub fn global(self, global: bool) -> Self

Offer this option in every subcommand below its command, too.

Source

pub fn heading(self, heading: impl Into<String>) -> Self

Source

pub fn takes_value(&self) -> bool

Whether the argument takes a value.

Source

pub fn choice_list(&self) -> &[Choice]

The allowed values, if restricted.

Source

pub fn group(&self) -> &str

The help group this argument belongs to.

Source

pub fn metavar(&self) -> Option<String>

The metavar as displayed: <NAME> (plus ... when multiple), or the name unchanged when it already carries brackets.

Source

pub fn switches(&self) -> Vec<String>

Every command-line spelling: -s and its short aliases, --long, then --aliases.

Source

pub fn names(&self) -> String

The names as help shows them: -w, --width <SIZE>; a positional shows only its metavar.

Source

pub fn primary(&self) -> String

The primary switch: --long, else -s, else the id.

Trait Implementations§

Source§

impl Clone for ArgSpec

Source§

fn clone(&self) -> Self

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 ArgSpec

Source§

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

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

impl Default for ArgSpec

Source§

fn default() -> Self

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

impl Eq for ArgSpec

Source§

impl PartialEq for ArgSpec

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 StructuralPartialEq for ArgSpec

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more