Skip to content

Commit

Permalink
fix(help): fixes a bug where requirements are included as program nam…
Browse files Browse the repository at this point in the history
…e in help and version
  • Loading branch information
kbknapp committed May 18, 2015
1 parent a3ceb7a commit 08ba3f2
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ pub struct App<'a, 'v, 'ab, 'u, 'h, 'ar> {
blacklist: HashSet<&'ar str>,
usage_str: Option<&'u str>,
bin_name: Option<String>,
usage: Option<String>,
groups: HashMap<&'ar str, ArgGroup<'ar, 'ar>>,
no_sc_error: bool
}
Expand Down Expand Up @@ -155,6 +156,7 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
short_list: HashSet::new(),
long_list: HashSet::new(),
usage_str: None,
usage: None,
blacklist: HashSet::new(),
bin_name: None,
groups: HashMap::new(),
Expand Down Expand Up @@ -951,10 +953,10 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
let r_string = reqs.iter().fold(String::new(), |acc, s| acc + &format!(" {}", s)[..]);

usage.push_str(&format!("{}{}",
self.bin_name.clone().unwrap_or(self.name.clone()),
self.usage.clone().unwrap_or(self.bin_name.clone().unwrap_or(self.name.clone())),
r_string)[..]);
} else {
usage.push_str(&self.bin_name.clone().unwrap_or(self.name.clone())[..]);
usage.push_str(&self.usage.clone().unwrap_or(self.bin_name.clone().unwrap_or(self.name.clone()))[..]);

let mut reqs = self.required.iter().map(|n| *n).collect::<Vec<_>>();
// If it's required we also need to ensure all previous positionals are required too
Expand Down Expand Up @@ -1668,14 +1670,22 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
let mut new_matches = ArgMatches::new();
// bin_name should be parent's bin_name + [<reqs>] + the sc's name separated by a
// space
sc.bin_name = Some(format!("{}{}{}",
sc.usage = Some(format!("{}{}{}",
self.bin_name.clone().unwrap_or("".to_owned()),
if self.bin_name.is_some() {
mid_string
} else {
"".to_owned()
},
sc.name.clone()));
sc.bin_name = Some(format!("{}{}{}",
self.bin_name.clone().unwrap_or("".to_owned()),
if self.bin_name.is_some() {
" "
} else {
""
},
sc.name.clone()));
sc.get_matches_from(&mut new_matches, it);
matches.subcommand = Some(Box::new(SubCommand {
name: sc.name_slice,
Expand Down

0 comments on commit 08ba3f2

Please sign in to comment.