mirror of
https://github.com/clap-rs/clap
synced 2024-12-15 15:22:30 +00:00
documentation for ArgValue
This commit is contained in:
parent
d53778ed5d
commit
47ff3ed945
1 changed files with 42 additions and 4 deletions
|
@ -65,12 +65,28 @@ impl<'help> ArgValue<'help> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// TODO
|
/// Returns all valid values of the argument value.
|
||||||
|
/// Namely the name and all aliases.
|
||||||
pub fn get_name_and_aliases(&self) -> impl Iterator<Item = &str> {
|
pub fn get_name_and_aliases(&self) -> impl Iterator<Item = &str> {
|
||||||
iter::once(&self.name).chain(&self.aliases).copied()
|
iter::once(&self.name).chain(&self.aliases).copied()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// TODO
|
/// Tests if the value is valid for this argument value
|
||||||
|
///
|
||||||
|
/// The value is valid if it is either the name or one of the aliases.
|
||||||
|
///
|
||||||
|
/// # Examples
|
||||||
|
///
|
||||||
|
/// ```rust
|
||||||
|
/// # use clap::ArgValue;
|
||||||
|
/// let arg_value = ArgValue::new("fast").alias("not-slow");
|
||||||
|
///
|
||||||
|
/// assert!(arg_value.matches("fast", false));
|
||||||
|
/// assert!(arg_value.matches("not-slow", false));
|
||||||
|
///
|
||||||
|
/// assert!(arg_value.matches("FAST", true));
|
||||||
|
/// assert!(!arg_value.matches("FAST", false));
|
||||||
|
/// ```
|
||||||
pub fn matches(&self, value: &str, ignore_case: bool) -> bool {
|
pub fn matches(&self, value: &str, ignore_case: bool) -> bool {
|
||||||
if ignore_case {
|
if ignore_case {
|
||||||
self.get_name_and_aliases()
|
self.get_name_and_aliases()
|
||||||
|
@ -142,13 +158,35 @@ impl<'help> ArgValue<'help> {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// TODO
|
/// Sets an alias for this argument value.
|
||||||
|
///
|
||||||
|
/// The alias will be hidden from completion and help texts.
|
||||||
|
///
|
||||||
|
/// # Examples
|
||||||
|
///
|
||||||
|
/// ```rust
|
||||||
|
/// # use clap::ArgValue;
|
||||||
|
/// ArgValue::new("slow")
|
||||||
|
/// .alias("not-fast")
|
||||||
|
/// # ;
|
||||||
|
/// ```
|
||||||
pub fn alias(mut self, name: &'help str) -> Self {
|
pub fn alias(mut self, name: &'help str) -> Self {
|
||||||
self.aliases.push(name);
|
self.aliases.push(name);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// TODO
|
/// Sets multiple aliases for this argument value.
|
||||||
|
///
|
||||||
|
/// The aliases will be hidden from completion and help texts.
|
||||||
|
///
|
||||||
|
/// # Examples
|
||||||
|
///
|
||||||
|
/// ```rust
|
||||||
|
/// # use clap::ArgValue;
|
||||||
|
/// ArgValue::new("slow")
|
||||||
|
/// .aliases(["not-fast", "snake-like"])
|
||||||
|
/// # ;
|
||||||
|
/// ```
|
||||||
pub fn aliases<I>(mut self, names: I) -> Self
|
pub fn aliases<I>(mut self, names: I) -> Self
|
||||||
where
|
where
|
||||||
I: IntoIterator<Item = &'help str>,
|
I: IntoIterator<Item = &'help str>,
|
||||||
|
|
Loading…
Reference in a new issue