diff --git a/src/app/mod.rs b/src/app/mod.rs index 4473f9a1..428bcdbd 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -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>(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. diff --git a/tests/app_settings.rs b/tests/app_settings.rs index c8cb90a7..3b2a34bc 100644 --- a/tests/app_settings.rs +++ b/tests/app_settings.rs @@ -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")); -} \ No newline at end of file +}