Skip to content

Commit dd8f21c

Browse files
committed
imp(usage): usage strings now include parent command requirements
Closes #125
1 parent 4a4229f commit dd8f21c

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/app.rs

+13-5
Original file line numberDiff line numberDiff line change
@@ -1461,8 +1461,6 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
14611461
// previous positionals too. This will denote where to start
14621462
// let mut req_pos_from_name = None;
14631463
if let Some(p) = self.positionals_idx.get(&pos_counter) {
1464-
1465-
14661464
if self.blacklist.contains(p.name) {
14671465
matches.args.remove(p.name);
14681466
self.report_error(format!("The argument '{}' cannot be used with {}",
@@ -1641,15 +1639,25 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
16411639
matches.usage = Some(self.create_usage(None));
16421640

16431641
if let Some(sc_name) = subcmd_name {
1642+
let mut mid_string = String::new();
1643+
if !self.subcmds_neg_reqs {
1644+
let mut hs = self.required.iter().map(|n| *n).collect::<Vec<_>>();
1645+
matches.args.keys().map(|k| hs.push(*k)).collect::<Vec<_>>();
1646+
let reqs = self.get_required_from(hs);
1647+
1648+
mid_string.push_str(&reqs.iter().fold(String::new(), |acc, s| acc + &format!(" {}", s)[..])[..])
1649+
}
1650+
mid_string.push_str(" ");
16441651
if let Some(ref mut sc) = self.subcommands.get_mut(&sc_name) {
16451652
let mut new_matches = ArgMatches::new();
1646-
// bin_name should be parent's bin_name + the sc's name separated by a space
1653+
// bin_name should be parent's bin_name + [<reqs>] + the sc's name separated by a
1654+
// space
16471655
sc.bin_name = Some(format!("{}{}{}",
16481656
self.bin_name.clone().unwrap_or("".to_owned()),
16491657
if self.bin_name.is_some() {
1650-
" "
1658+
mid_string
16511659
} else {
1652-
""
1660+
"".to_owned()
16531661
},
16541662
sc.name.clone()));
16551663
sc.get_matches_from(&mut new_matches, it);

0 commit comments

Comments
 (0)