Skip to content

Commit

Permalink
api(App::name): adds the ability to change the name of the App instan…
Browse files Browse the repository at this point in the history
…ce after creation

Closes #908
  • Loading branch information
SuperFluffy authored and kbknapp committed Mar 23, 2017
1 parent 6b491c1 commit d49e829
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
27 changes: 27 additions & 0 deletions src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,33 @@ impl<'a, 'b> App<'a, 'b> {
self
}

/// Sets the program's name. This will be displayed when displaying help information.
///
/// **Pro-top:** This function is particularly useful when configuring a program via
/// [`App::from_yaml`] in conjunction with the [`crate_name!`] macro to derive the program's
/// name from its `Cargo.toml`.
///
/// # Examples
/// ```ignore
/// # #[macro_use]
/// # extern crate clap;
/// # use clap::App;
/// # fn main() {
/// let yml = load_yaml!("app.yml");
/// let app = App::from_yaml(yml)
/// .name(crate_name!());
///
/// // continued logic goes here, such as `app.get_matches()` etc.
/// # }
/// ```
///
/// [`App::from_yaml`]: ./struct.App.html#method.from_yaml
/// [`crate_name!`]: ./macro.crate_name.html
pub fn name<S: Into<String>>(mut self, name: S) -> Self {
self.p.meta.name = name.into();
self
}

/// Adds additional help information to be displayed in addition to auto-generated help. This
/// information is displayed **after** the auto-generated help information. This is often used
/// to describe how to use the arguments, or caveats to be noted.
Expand Down
5 changes: 3 additions & 2 deletions tests/app_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ fn no_bin_name() {

#[test]
fn unified_help() {
let app = App::new("test")
let app = App::new("myTest")
.name("test")
.author("Kevin K.")
.about("tests stuff")
.version("1.3")
Expand Down Expand Up @@ -618,4 +619,4 @@ fn allow_missing_positional() {
let m = m.unwrap();
assert_eq!(m.value_of("src"), Some("src"));
assert_eq!(m.value_of("dest"), Some("file"));
}
}

0 comments on commit d49e829

Please sign in to comment.