@@ -5,6 +5,8 @@ use cargo::{self, drop_print, drop_println, CliResult, Config};
5
5
use clap:: { AppSettings , Arg , ArgMatches } ;
6
6
use itertools:: Itertools ;
7
7
use std:: collections:: HashMap ;
8
+ use std:: ffi:: OsStr ;
9
+ use std:: ffi:: OsString ;
8
10
use std:: fmt:: Write ;
9
11
10
12
use super :: commands;
@@ -241,20 +243,20 @@ fn expand_aliases(
241
243
}
242
244
( Some ( _) , None ) => {
243
245
// Command is built-in and is not conflicting with alias, but contains ignored values.
244
- if let Some ( mut values) = args. get_many :: < String > ( "" ) {
246
+ if let Some ( values) = args. get_many :: < OsString > ( "" ) {
245
247
return Err ( anyhow:: format_err!(
246
248
"\
247
249
trailing arguments after built-in command `{}` are unsupported: `{}`
248
250
249
251
To pass the arguments to the subcommand, remove `--`" ,
250
252
cmd,
251
- values. join( " " ) ,
253
+ values. map ( |s| s . to_string_lossy ( ) ) . join( " " ) ,
252
254
)
253
255
. into ( ) ) ;
254
256
}
255
257
}
256
258
( None , None ) => { }
257
- ( _, Some ( mut alias) ) => {
259
+ ( _, Some ( alias) ) => {
258
260
// Check if this alias is shadowing an external subcommand
259
261
// (binary of the form `cargo-<subcommand>`)
260
262
// Currently this is only a warning, but after a transition period this will become
@@ -270,7 +272,11 @@ For more information, see issue #10049 <https://github.com/rust-lang/cargo/issue
270
272
) ) ?;
271
273
}
272
274
273
- alias. extend ( args. get_many :: < String > ( "" ) . unwrap_or_default ( ) . cloned ( ) ) ;
275
+ let mut alias = alias
276
+ . into_iter ( )
277
+ . map ( |s| OsString :: from ( s) )
278
+ . collect :: < Vec < _ > > ( ) ;
279
+ alias. extend ( args. get_many :: < OsString > ( "" ) . unwrap_or_default ( ) . cloned ( ) ) ;
274
280
// new_args strips out everything before the subcommand, so
275
281
// capture those global options now.
276
282
// Note that an alias to an external command will not receive
@@ -346,12 +352,12 @@ fn execute_subcommand(config: &mut Config, cmd: &str, subcommand_args: &ArgMatch
346
352
return exec ( config, subcommand_args) ;
347
353
}
348
354
349
- let mut ext_args: Vec < & str > = vec ! [ cmd] ;
355
+ let mut ext_args: Vec < & OsStr > = vec ! [ OsStr :: new ( cmd) ] ;
350
356
ext_args. extend (
351
357
subcommand_args
352
- . get_many :: < String > ( "" )
358
+ . get_many :: < OsString > ( "" )
353
359
. unwrap_or_default ( )
354
- . map ( String :: as_str ) ,
360
+ . map ( OsString :: as_os_str ) ,
355
361
) ;
356
362
super :: execute_external_subcommand ( config, cmd, & ext_args)
357
363
}
@@ -400,6 +406,7 @@ pub fn cli() -> App {
400
406
} ;
401
407
App :: new ( "cargo" )
402
408
. allow_external_subcommands ( true )
409
+ . allow_invalid_utf8_for_external_subcommands ( true )
403
410
. setting ( AppSettings :: DeriveDisplayOrder )
404
411
// Doesn't mix well with our list of common cargo commands. See clap-rs/clap#3108 for
405
412
// opening clap up to allow us to style our help template
0 commit comments