Skip to content

Commit

Permalink
fix: prints the name in version and help instead of binary name
Browse files Browse the repository at this point in the history
  • Loading branch information
kbknapp committed Jan 4, 2016
1 parent ea83a3d commit 8f3817f
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/app/mod.rs
Expand Up @@ -1092,8 +1092,7 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar> {
}

// Creates a context aware usage string, or "smart usage" from currently used
// args, and
// requirements
// args, and requirements
fn usage_from_matcher(&self, usage: &mut String, matcher: &[&'ar str]) -> ClapResult<()> {
use std::fmt::Write;
let mut hs: Vec<&str> = self.required.iter().map(|n| *n).collect();
Expand Down Expand Up @@ -1148,10 +1147,7 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar> {
}

// Print the version
try!(write!(w,
"{} {}\n",
&self.bin_name.as_ref().unwrap_or(&self.name)[..].replace(" ", "-"),
self.version.unwrap_or("")));
try!(self.write_version(w));
let flags = !self.flags.is_empty();
let pos = !self.positionals.is_empty();
let opts = !self.opts.is_empty();
Expand Down Expand Up @@ -1882,17 +1878,23 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar> {

// Prints the version to the user and exits if quit=true
fn print_version<W: Write>(&self, w: &mut W) -> ClapResult<()> {
// Print the binary name if existing, but replace all spaces with hyphens in
// case we're
// dealing with subcommands i.e. git mv is translated to git-mv
try!(writeln!(w,
"{} {}",
&self.bin_name.as_ref().unwrap_or(&self.name)[..].replace(" ", "-"),
self.version.unwrap_or("")));

try!(self.write_version(w));
w.flush().map_err(ClapError::from)
}

fn write_version<W: Write>(&self, w: &mut W) -> io::Result<()> {
if let Some(bn) = self.bin_name.as_ref() {
if bn.contains(" ") {
// Incase we're dealing with subcommands i.e. git mv is translated to git-mv
writeln!(w, "{} {}", bn.replace(" ", "-"), self.version.unwrap_or(""))
} else {
writeln!(w, "{} {}", &self.name[..], self.version.unwrap_or(""))
}
} else {
writeln!(w, "{} {}", &self.name[..], self.version.unwrap_or(""))
}
}

#[doc(hidden)]
pub fn create_current_usage(&self, matcher: &ArgMatcher) -> ClapResult<String> {
self.create_usage(&matcher.arg_names()
Expand Down

0 comments on commit 8f3817f

Please sign in to comment.