mirror of
https://github.com/clap-rs/clap
synced 2025-03-04 23:37:32 +00:00
Merge pull request #2368 from integer32llc/more-getters
Allow getting the long about, env, and default values of an argument
This commit is contained in:
commit
09009761ec
1 changed files with 42 additions and 0 deletions
|
@ -133,6 +133,21 @@ impl<'help> Arg<'help> {
|
|||
self.about
|
||||
}
|
||||
|
||||
/// Get the long help specified for this argument, if any
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust
|
||||
/// # use clap::Arg;
|
||||
/// let arg = Arg::new("foo").long_about("long about");
|
||||
/// assert_eq!(Some("long about"), arg.get_long_about());
|
||||
/// ```
|
||||
///
|
||||
#[inline]
|
||||
pub fn get_long_about(&self) -> Option<&str> {
|
||||
self.long_about
|
||||
}
|
||||
|
||||
/// Get the help heading specified for this argument, if any
|
||||
#[inline]
|
||||
pub fn get_help_heading(&self) -> Option<&str> {
|
||||
|
@ -234,6 +249,33 @@ impl<'help> Arg<'help> {
|
|||
pub fn get_global(&self) -> bool {
|
||||
self.global
|
||||
}
|
||||
|
||||
/// Get the environment variable name specified for this argument, if any
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust
|
||||
/// # use std::ffi::OsStr;
|
||||
/// # use clap::Arg;
|
||||
/// let arg = Arg::new("foo").env("ENVIRONMENT");
|
||||
/// assert_eq!(Some(OsStr::new("ENVIRONMENT")), arg.get_env());
|
||||
/// ```
|
||||
pub fn get_env(&self) -> Option<&OsStr> {
|
||||
self.env.as_ref().map(|x| x.0)
|
||||
}
|
||||
|
||||
/// Get the default values specified for this argument, if any
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust
|
||||
/// # use clap::Arg;
|
||||
/// let arg = Arg::new("foo").default_value("default value");
|
||||
/// assert_eq!(&["default value"], arg.get_default_values());
|
||||
/// ```
|
||||
pub fn get_default_values(&self) -> &[&OsStr] {
|
||||
&self.default_vals
|
||||
}
|
||||
}
|
||||
|
||||
impl<'help> Arg<'help> {
|
||||
|
|
Loading…
Add table
Reference in a new issue