Skip to content

Commit eb0e374

Browse files
committed
fix(usage strings): positional arguments are presented in index order
Positional arguments are now presented in index order in suggested usage strings which prevents out of order suggestions. Closes #112
1 parent 4903add commit eb0e374

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/app.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::collections::BTreeMap;
22
use std::collections::BTreeSet;
33
use std::collections::HashSet;
44
use std::collections::HashMap;
5+
use std::collections::VecDeque;
56
use std::env;
67
use std::path::Path;
78
use std::vec::IntoIter;
@@ -765,7 +766,7 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
765766
.fold(vec![], |acc, v| acc + &v)
766767
}
767768

768-
fn get_required_from(&self, reqs: HashSet<&'ar str>) -> Vec<String> {
769+
fn get_required_from(&self, reqs: HashSet<&'ar str>) -> VecDeque<String> {
769770
let mut c_flags = HashSet::new();
770771
let mut c_pos = HashSet::new();
771772
let mut c_opt = HashSet::new();
@@ -852,27 +853,29 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
852853
}
853854

854855

855-
let mut ret_val = vec![];
856+
let mut ret_val = VecDeque::new();
856857

858+
let mut pmap = BTreeMap::new();
857859
for p in &c_pos {
858860
if let Some(idx) = self.positionals_name.get(p) {
859861
if let Some(ref p) = self.positionals_idx.get(&idx) {
860-
ret_val.push(format!("{}", p));
862+
pmap.insert(p.index, format!("{}", p));
861863
}
862864
}
863865
}
866+
pmap.into_iter().map(|(_, s)| ret_val.push_back(s)).collect::<Vec<_>>();
864867
for f in &c_flags {
865-
ret_val.push(format!("{}", self.flags.get(*f).unwrap()));
868+
ret_val.push_back(format!("{}", self.flags.get(*f).unwrap()));
866869
}
867870
for o in &c_opt {
868-
ret_val.push(format!("{}", self.opts.get(*o).unwrap()));
871+
ret_val.push_back(format!("{}", self.opts.get(*o).unwrap()));
869872
}
870873
for g in grps {
871874
let g_string = self.get_group_members(g).iter()
872875
.fold(String::new(), |acc, s| {
873876
acc + &format!(" {} |",s)[..]
874877
});
875-
ret_val.push(format!("[{}]", &g_string[..g_string.len()-1]));
878+
ret_val.push_back(format!("[{}]", &g_string[..g_string.len()-1]));
876879
}
877880

878881
ret_val

0 commit comments

Comments
 (0)