@@ -96,45 +96,42 @@ pub fn is_manifest_command(arg: &str) -> bool {
9696
9797pub fn exec_manifest_command ( gctx : & mut GlobalContext , cmd : & str , args : & [ OsString ] ) -> CliResult {
9898 let manifest_path = Path :: new ( cmd) ;
99- match manifest_path. is_file ( ) {
100- true => { }
101- false => {
102- let possible_commands = crate :: list_commands ( gctx) ;
103- let is_dir = if manifest_path. is_dir ( ) {
104- format ! ( ": `{cmd}` is a directory" )
105- } else {
99+ if !manifest_path. is_file ( ) {
100+ let possible_commands = crate :: list_commands ( gctx) ;
101+ let is_dir = if manifest_path. is_dir ( ) {
102+ format ! ( ": `{cmd}` is a directory" )
103+ } else {
104+ "" . to_owned ( )
105+ } ;
106+ let suggested_command = if let Some ( suggested_command) = possible_commands
107+ . keys ( )
108+ . filter ( |c| cmd. starts_with ( c. as_str ( ) ) )
109+ . max_by_key ( |c| c. len ( ) )
110+ {
111+ let actual_args = cmd. strip_prefix ( suggested_command) . unwrap ( ) ;
112+ let args = if args. is_empty ( ) {
106113 "" . to_owned ( )
107- } ;
108- let suggested_command = if let Some ( suggested_command) = possible_commands
109- . keys ( )
110- . filter ( |c| cmd. starts_with ( c. as_str ( ) ) )
111- . max_by_key ( |c| c. len ( ) )
112- {
113- let actual_args = cmd. strip_prefix ( suggested_command) . unwrap ( ) ;
114- let args = if args. is_empty ( ) {
115- "" . to_owned ( )
116- } else {
117- format ! (
118- " {}" ,
119- args. into_iter( ) . map( |os| os. to_string_lossy( ) ) . join( " " )
120- )
121- } ;
114+ } else {
122115 format ! (
123- "\n help: there is a command with a similar name: `{suggested_command} {actual_args}{args}`"
116+ " {}" ,
117+ args. into_iter( ) . map( |os| os. to_string_lossy( ) ) . join( " " )
124118 )
125- } else {
126- "" . to_owned ( )
127- } ;
128- let suggested_script = if let Some ( suggested_script) = suggested_script ( cmd) {
129- format ! ( "\n help: there is a script with a similar name: `{suggested_script}`" )
130- } else {
131- "" . to_owned ( )
132119 } ;
133- return Err ( anyhow :: anyhow !(
134- "no such file or subcommand `{cmd}`{is_dir}{suggested_command}{suggested_script} "
120+ format ! (
121+ "\n help: there is a command with a similar name: `{suggested_command} {actual_args}{args}` "
135122 )
136- . into ( ) ) ;
137- }
123+ } else {
124+ "" . to_owned ( )
125+ } ;
126+ let suggested_script = if let Some ( suggested_script) = suggested_script ( cmd) {
127+ format ! ( "\n help: there is a script with a similar name: `{suggested_script}`" )
128+ } else {
129+ "" . to_owned ( )
130+ } ;
131+ return Err ( anyhow:: anyhow!(
132+ "no such file or subcommand `{cmd}`{is_dir}{suggested_command}{suggested_script}"
133+ )
134+ . into ( ) ) ;
138135 }
139136
140137 let manifest_path = root_manifest ( Some ( manifest_path) , gctx) ?;
0 commit comments