imp(Binary Names): allows users to override the system determined bin name

Allows users to use `.bin_name("name")` to override the system
determined name with one of their choosing.

Closes #134
This commit is contained in:
Kevin K 2015-05-30 13:09:21 -04:00
parent 6f76bd0a07
commit 2191fe94bd

View file

@ -186,6 +186,25 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
self
}
/// Overrides the system-determined binary name. This should only be used when absolutely
/// neccessary, such as the binary name for your application is misleading, or perhaps *not*
/// how the user should invoke your program.
///
/// **NOTE:** This command __**should not**__ be used for SubCommands.
///
/// # Example
///
/// ```no_run
/// # use clap::{App, Arg};
/// # let app = App::new("myprog")
/// .bin_name("my_binary")
/// # .get_matches();
/// ```
pub fn bin_name(mut self, a: &str) -> App<'a, 'v, 'ab, 'u, 'h, 'ar> {
self.bin_name = Some(a.to_owned());
self
}
/// Sets a string briefly describing what the program does and will be displayed when
/// displaying help information.
///
@ -1310,7 +1329,9 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
let p = Path::new(&name[..]);
if let Some(f) = p.file_name() {
if let Ok(s) = f.to_os_string().into_string() {
self.bin_name = Some(s);
if let None = self.bin_name {
self.bin_name = Some(s);
}
}
}
}