6
6
// Std
7
7
use std:: borrow:: Cow ;
8
8
use std:: cmp;
9
+ use std:: collections:: BTreeMap ;
9
10
10
11
// Internal
11
12
use crate :: builder:: PossibleValue ;
@@ -467,7 +468,7 @@ impl HelpTemplate<'_, '_> {
467
468
debug ! ( "HelpTemplate::write_args {_category}" ) ;
468
469
// The shortest an arg can legally be is 2 (i.e. '-x')
469
470
let mut longest = 2 ;
470
- let mut ord_v = Vec :: new ( ) ;
471
+ let mut ord_v = BTreeMap :: new ( ) ;
471
472
472
473
// Determine the longest
473
474
for & arg in args. iter ( ) . filter ( |arg| {
@@ -486,9 +487,8 @@ impl HelpTemplate<'_, '_> {
486
487
}
487
488
488
489
let key = ( sort_key) ( arg) ;
489
- ord_v. push ( ( key, arg) ) ;
490
+ ord_v. insert ( key, arg) ;
490
491
}
491
- ord_v. sort_by ( |a, b| a. 0 . cmp ( & b. 0 ) ) ;
492
492
493
493
let next_line_help = self . will_args_wrap ( args, longest) ;
494
494
@@ -858,19 +858,17 @@ impl HelpTemplate<'_, '_> {
858
858
use std:: fmt:: Write as _;
859
859
let header = & self . styles . get_header ( ) ;
860
860
861
- let mut ord_v = Vec :: new ( ) ;
861
+ let mut ord_v = BTreeMap :: new ( ) ;
862
862
for subcommand in cmd
863
863
. get_subcommands ( )
864
864
. filter ( |subcommand| should_show_subcommand ( subcommand) )
865
865
{
866
- ord_v. push ( (
867
- subcommand. get_display_order ( ) ,
868
- subcommand. get_name ( ) ,
866
+ ord_v. insert (
867
+ ( subcommand. get_display_order ( ) , subcommand. get_name ( ) ) ,
869
868
subcommand,
870
- ) ) ;
869
+ ) ;
871
870
}
872
- ord_v. sort_by ( |a, b| ( a. 0 , & a. 1 ) . cmp ( & ( b. 0 , & b. 1 ) ) ) ;
873
- for ( _, _, subcommand) in ord_v {
871
+ for ( _, subcommand) in ord_v {
874
872
if !* first {
875
873
self . writer . push_str ( "\n \n " ) ;
876
874
}
@@ -915,7 +913,7 @@ impl HelpTemplate<'_, '_> {
915
913
916
914
// The shortest an arg can legally be is 2 (i.e. '-x')
917
915
let mut longest = 2 ;
918
- let mut ord_v = Vec :: new ( ) ;
916
+ let mut ord_v = BTreeMap :: new ( ) ;
919
917
for subcommand in cmd
920
918
. get_subcommands ( )
921
919
. filter ( |subcommand| should_show_subcommand ( subcommand) )
@@ -930,19 +928,18 @@ impl HelpTemplate<'_, '_> {
930
928
let _ = write ! ( styled, ", {literal}--{long}{literal:#}" , ) ;
931
929
}
932
930
longest = longest. max ( styled. display_width ( ) ) ;
933
- ord_v. push ( ( subcommand. get_display_order ( ) , styled, subcommand) ) ;
931
+ ord_v. insert ( ( subcommand. get_display_order ( ) , styled) , subcommand) ;
934
932
}
935
- ord_v. sort_by ( |a, b| ( a. 0 , & a. 1 ) . cmp ( & ( b. 0 , & b. 1 ) ) ) ;
936
933
937
934
debug ! ( "HelpTemplate::write_subcommands longest = {longest}" ) ;
938
935
939
936
let next_line_help = self . will_subcommands_wrap ( cmd. get_subcommands ( ) , longest) ;
940
937
941
- for ( i, ( _ , sc_str, sc) ) in ord_v. into_iter ( ) . enumerate ( ) {
938
+ for ( i, ( sc_str, sc) ) in ord_v. into_iter ( ) . enumerate ( ) {
942
939
if 0 < i {
943
940
self . writer . push_str ( "\n " ) ;
944
941
}
945
- self . write_subcommand ( sc_str, sc, next_line_help, longest) ;
942
+ self . write_subcommand ( sc_str. 1 , sc, next_line_help, longest) ;
946
943
}
947
944
}
948
945
0 commit comments