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:
Pavan Kumar Sunkara 2021-03-05 22:53:28 +05:30 committed by GitHub
commit 09009761ec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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> {