api(App::name): adds the ability to change the name of the App instance after creation

Closes #908
This commit is contained in:
Richard Janis Goldschmidt 2017-03-21 11:00:30 +01:00 committed by Kevin K
parent 6b491c1161
commit d49e8292b0
No known key found for this signature in database
GPG key ID: 17218E4B3692F01A
2 changed files with 30 additions and 2 deletions

View file

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

View file

@ -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")
@ -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"));
}
}