@@ -10,7 +10,7 @@ use std::fs;
10
10
use std:: path:: { Path , PathBuf } ;
11
11
12
12
use cargo:: core:: shell:: Shell ;
13
- use cargo:: util:: { self , command_prelude , lev_distance , CargoResult , CliResult , Config } ;
13
+ use cargo:: util:: { self , closest_msg , command_prelude , CargoResult , CliResult , Config } ;
14
14
use cargo:: util:: { CliError , ProcessError } ;
15
15
16
16
mod cli;
@@ -113,18 +113,6 @@ fn list_commands(config: &Config) -> BTreeSet<CommandInfo> {
113
113
commands
114
114
}
115
115
116
- fn find_closest ( config : & Config , cmd : & str ) -> Option < String > {
117
- let cmds = list_commands ( config) ;
118
- // Only consider candidates with a lev_distance of 3 or less so we don't
119
- // suggest out-of-the-blue options.
120
- cmds. into_iter ( )
121
- . map ( |c| c. name ( ) )
122
- . map ( |c| ( lev_distance ( & c, cmd) , c) )
123
- . filter ( |& ( d, _) | d < 4 )
124
- . min_by_key ( |a| a. 0 )
125
- . map ( |slot| slot. 1 )
126
- }
127
-
128
116
fn execute_external_subcommand ( config : & Config , cmd : & str , args : & [ & str ] ) -> CliResult {
129
117
let command_exe = format ! ( "cargo-{}{}" , cmd, env:: consts:: EXE_SUFFIX ) ;
130
118
let path = search_directories ( config)
@@ -134,14 +122,9 @@ fn execute_external_subcommand(config: &Config, cmd: &str, args: &[&str]) -> Cli
134
122
let command = match path {
135
123
Some ( command) => command,
136
124
None => {
137
- let err = match find_closest ( config, cmd) {
138
- Some ( closest) => failure:: format_err!(
139
- "no such subcommand: `{}`\n \n \t Did you mean `{}`?\n " ,
140
- cmd,
141
- closest
142
- ) ,
143
- None => failure:: format_err!( "no such subcommand: `{}`" , cmd) ,
144
- } ;
125
+ let cmds = list_commands ( config) ;
126
+ let did_you_mean = closest_msg ( cmd, cmds. iter ( ) , |c| c. name ( ) ) ;
127
+ let err = failure:: format_err!( "no such subcommand: `{}`{}" , cmd, did_you_mean) ;
145
128
return Err ( CliError :: new ( err, 101 ) ) ;
146
129
}
147
130
} ;
0 commit comments