@@ -8,7 +8,7 @@ use cargo::util::toml::StringOrVec;
88use cargo:: util:: CliError ;
99use cargo:: util:: { self , closest_msg, command_prelude, CargoResult , CliResult , Config } ;
1010use cargo_util:: { ProcessBuilder , ProcessError } ;
11- use std:: collections:: { BTreeMap , BTreeSet } ;
11+ use std:: collections:: BTreeMap ;
1212use std:: env;
1313use std:: fs;
1414use std:: path:: { Path , PathBuf } ;
@@ -84,10 +84,10 @@ fn aliased_command(config: &Config, command: &str) -> CargoResult<Option<Vec<Str
8484}
8585
8686/// List all runnable commands
87- fn list_commands ( config : & Config ) -> BTreeSet < CommandInfo > {
87+ fn list_commands ( config : & Config ) -> BTreeMap < String , CommandInfo > {
8888 let prefix = "cargo-" ;
8989 let suffix = env:: consts:: EXE_SUFFIX ;
90- let mut commands = BTreeSet :: new ( ) ;
90+ let mut commands = BTreeMap :: new ( ) ;
9191 for dir in search_directories ( config) {
9292 let entries = match fs:: read_dir ( dir) {
9393 Ok ( entries) => entries,
@@ -104,37 +104,43 @@ fn list_commands(config: &Config) -> BTreeSet<CommandInfo> {
104104 }
105105 if is_executable ( entry. path ( ) ) {
106106 let end = filename. len ( ) - suffix. len ( ) ;
107- commands. insert ( CommandInfo :: External {
108- name : filename[ prefix. len ( ) ..end] . to_string ( ) ,
109- path : path. clone ( ) ,
110- } ) ;
107+ commands. insert (
108+ filename[ prefix. len ( ) ..end] . to_string ( ) ,
109+ CommandInfo :: External { path : path. clone ( ) } ,
110+ ) ;
111111 }
112112 }
113113 }
114114
115115 for cmd in commands:: builtin ( ) {
116- commands. insert ( CommandInfo :: BuiltIn {
117- name : cmd. get_name ( ) . to_string ( ) ,
118- about : cmd. p . meta . about . map ( |s| s. to_string ( ) ) ,
119- } ) ;
116+ commands. insert (
117+ cmd. get_name ( ) . to_string ( ) ,
118+ CommandInfo :: BuiltIn {
119+ about : cmd. p . meta . about . map ( |s| s. to_string ( ) ) ,
120+ } ,
121+ ) ;
120122 }
121123
122124 // Add the builtin_aliases and them descriptions to the
123- // `commands` `BTreeSet `.
125+ // `commands` `BTreeMap `.
124126 for command in & BUILTIN_ALIASES {
125- commands. insert ( CommandInfo :: BuiltIn {
126- name : command. 0 . to_string ( ) ,
127- about : Some ( command. 2 . to_string ( ) ) ,
128- } ) ;
127+ commands. insert (
128+ command. 0 . to_string ( ) ,
129+ CommandInfo :: BuiltIn {
130+ about : Some ( command. 2 . to_string ( ) ) ,
131+ } ,
132+ ) ;
129133 }
130134
131135 // Add the user-defined aliases
132136 if let Ok ( aliases) = config. get :: < BTreeMap < String , StringOrVec > > ( "alias" ) {
133137 for ( name, target) in aliases. iter ( ) {
134- commands. insert ( CommandInfo :: Alias {
135- name : name. to_string ( ) ,
136- target : target. clone ( ) ,
137- } ) ;
138+ commands. insert (
139+ name. to_string ( ) ,
140+ CommandInfo :: Alias {
141+ target : target. clone ( ) ,
142+ } ,
143+ ) ;
138144 }
139145 }
140146
@@ -150,11 +156,8 @@ fn execute_external_subcommand(config: &Config, cmd: &str, args: &[&str]) -> Cli
150156 let command = match path {
151157 Some ( command) => command,
152158 None => {
153- let suggestions: Vec < _ > = list_commands ( config)
154- . iter ( )
155- . map ( |c| c. name ( ) . to_string ( ) )
156- . collect ( ) ;
157- let did_you_mean = closest_msg ( cmd, suggestions. iter ( ) , |c| c) ;
159+ let suggestions = list_commands ( config) ;
160+ let did_you_mean = closest_msg ( cmd, suggestions. keys ( ) , |c| c) ;
158161 let err = anyhow:: format_err!( "no such subcommand: `{}`{}" , cmd, did_you_mean) ;
159162 return Err ( CliError :: new ( err, 101 ) ) ;
160163 }
0 commit comments