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: StringA 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: boolWhether the argument may be given more than once (or takes a list).
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: boolA 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
impl ArgSpec
Sourcepub fn new(id: impl Into<String>) -> Self
pub fn new(id: impl Into<String>) -> Self
A bare argument with only an id; set the rest with the builders.
Sourcepub fn positional(name: impl Into<String>) -> Self
pub fn positional(name: impl Into<String>) -> Self
A positional argument shown as [NAME], or <NAME> when required.
pub fn long(self, long: impl Into<String>) -> Self
pub fn short(self, short: char) -> Self
pub fn alias(self, alias: impl Into<String>) -> Self
Sourcepub fn short_alias(self, short: char) -> Self
pub fn short_alias(self, short: char) -> Self
Another short name, listed after short.
Sourcepub fn value_name(self, name: impl Into<String>) -> Self
pub fn value_name(self, name: impl Into<String>) -> Self
Set the metavar; this also makes a flag take a value.
Sourcepub fn value(self, hint: ValueHint) -> Self
pub fn value(self, hint: ValueHint) -> Self
Set the value hint; a non-None hint makes a flag take a value.
Sourcepub fn choices<C: Into<Choice>>(
self,
choices: impl IntoIterator<Item = C>,
) -> Self
pub fn choices<C: Into<Choice>>( self, choices: impl IntoIterator<Item = C>, ) -> Self
Restrict the value to choices.
Sourcepub fn choice(self, value: impl Into<String>, help: impl Into<String>) -> Self
pub fn choice(self, value: impl Into<String>, help: impl Into<String>) -> Self
Add one allowed value with help.
pub fn help(self, help: impl Into<String>) -> Self
pub fn long_help(self, help: impl Into<String>) -> Self
pub fn default_value(self, value: impl Into<String>) -> Self
pub fn env(self, name: impl Into<String>) -> Self
pub fn config_key(self, key: impl Into<String>) -> Self
pub fn required(self, required: bool) -> Self
pub fn multiple(self, multiple: bool) -> Self
Sourcepub fn global(self, global: bool) -> Self
pub fn global(self, global: bool) -> Self
Offer this option in every subcommand below its command, too.
pub fn heading(self, heading: impl Into<String>) -> Self
Sourcepub fn takes_value(&self) -> bool
pub fn takes_value(&self) -> bool
Whether the argument takes a value.
Sourcepub fn choice_list(&self) -> &[Choice]
pub fn choice_list(&self) -> &[Choice]
The allowed values, if restricted.
Sourcepub fn metavar(&self) -> Option<String>
pub fn metavar(&self) -> Option<String>
The metavar as displayed: <NAME> (plus ... when multiple), or the
name unchanged when it already carries brackets.
Sourcepub fn switches(&self) -> Vec<String>
pub fn switches(&self) -> Vec<String>
Every command-line spelling: -s and its short aliases, --long,
then --aliases.
Trait Implementations§
impl Eq for ArgSpec
impl StructuralPartialEq for ArgSpec
Auto Trait Implementations§
impl Freeze for ArgSpec
impl RefUnwindSafe for ArgSpec
impl Send for ArgSpec
impl Sync for ArgSpec
impl Unpin for ArgSpec
impl UnsafeUnpin for ArgSpec
impl UnwindSafe for ArgSpec
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.