@@ -8,7 +8,7 @@ use cargo::util::toml::StringOrVec;
8
8
use cargo:: util:: CliError ;
9
9
use cargo:: util:: { self , closest_msg, command_prelude, CargoResult , CliResult , Config } ;
10
10
use cargo_util:: { ProcessBuilder , ProcessError } ;
11
- use std:: collections:: { BTreeMap , BTreeSet } ;
11
+ use std:: collections:: BTreeMap ;
12
12
use std:: env;
13
13
use std:: fs;
14
14
use std:: path:: { Path , PathBuf } ;
@@ -84,10 +84,10 @@ fn aliased_command(config: &Config, command: &str) -> CargoResult<Option<Vec<Str
84
84
}
85
85
86
86
/// List all runnable commands
87
- fn list_commands ( config : & Config ) -> BTreeSet < CommandInfo > {
87
+ fn list_commands ( config : & Config ) -> BTreeMap < String , CommandInfo > {
88
88
let prefix = "cargo-" ;
89
89
let suffix = env:: consts:: EXE_SUFFIX ;
90
- let mut commands = BTreeSet :: new ( ) ;
90
+ let mut commands = BTreeMap :: new ( ) ;
91
91
for dir in search_directories ( config) {
92
92
let entries = match fs:: read_dir ( dir) {
93
93
Ok ( entries) => entries,
@@ -104,37 +104,43 @@ fn list_commands(config: &Config) -> BTreeSet<CommandInfo> {
104
104
}
105
105
if is_executable ( entry. path ( ) ) {
106
106
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
+ ) ;
111
111
}
112
112
}
113
113
}
114
114
115
115
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
+ ) ;
120
122
}
121
123
122
124
// Add the builtin_aliases and them descriptions to the
123
- // `commands` `BTreeSet `.
125
+ // `commands` `BTreeMap `.
124
126
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
+ ) ;
129
133
}
130
134
131
135
// Add the user-defined aliases
132
136
if let Ok ( aliases) = config. get :: < BTreeMap < String , StringOrVec > > ( "alias" ) {
133
137
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
+ ) ;
138
144
}
139
145
}
140
146
@@ -150,11 +156,8 @@ fn execute_external_subcommand(config: &Config, cmd: &str, args: &[&str]) -> Cli
150
156
let command = match path {
151
157
Some ( command) => command,
152
158
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) ;
158
161
let err = anyhow:: format_err!( "no such subcommand: `{}`{}" , cmd, did_you_mean) ;
159
162
return Err ( CliError :: new ( err, 101 ) ) ;
160
163
}
0 commit comments