@@ -432,55 +432,18 @@ where
432432/// let result = handle_clap_result_with_exit_code(cmd, args, 125);
433433/// ```
434434pub fn handle_clap_result_with_exit_code < I , T > (
435- mut cmd : Command ,
435+ cmd : Command ,
436436 itr : I ,
437437 exit_code : i32 ,
438438) -> UResult < ArgMatches >
439439where
440440 I : IntoIterator < Item = T > ,
441441 T : Into < OsString > + Clone ,
442442{
443- // cloning args for double use in error case
444- let args = itr. into_iter ( ) . collect :: < Vec < T > > ( ) ;
445- let itr = args. clone ( ) ;
446- // using mut to avoid cloning cmd
447- cmd. try_get_matches_from_mut ( itr) . map_err ( |e| {
443+ cmd. try_get_matches_from ( itr) . map_err ( |e| {
448444 if e. exit_code ( ) == 0 {
449445 e. into ( ) // Preserve help/version
450446 } else {
451- if e. kind ( ) == ErrorKind :: UnknownArgument || e. kind ( ) == ErrorKind :: InvalidSubcommand {
452- // find ambiguous options
453- // Find the string the user actually typed (e.g., "--de")
454- // for arg in &itr {}
455- let args_str: Vec < String > = args
456- . into_iter ( )
457- . map ( |t| {
458- let o: OsString = t. into ( ) ;
459- o. to_string_lossy ( ) . to_string ( )
460- } )
461- . collect ( ) ;
462- if let Some ( provided) = args_str. iter ( ) . find ( |a| a. starts_with ( "--" ) ) {
463- let search_term = provided. trim_start_matches ( "--" ) ;
464-
465- // Manually filter all defined long arguments
466- let mut matches: Vec < _ > = cmd
467- . get_arguments ( )
468- . filter_map ( |arg| arg. get_long ( ) )
469- . filter ( |l| l. starts_with ( search_term) )
470- . collect ( ) ;
471-
472- if matches. len ( ) > 1 {
473- let mut msg =
474- translate ! ( "clap-error-ambiguous-argument" , "arg" => provided) ;
475- matches. sort ( ) ;
476- for m in matches {
477- msg. push_str ( & format ! ( "\n --{}" , m) ) ;
478- }
479- return USimpleError :: new ( exit_code, msg) ;
480- }
481- }
482- }
483-
484447 let formatter = ErrorFormatter :: new ( crate :: util_name ( ) ) ;
485448 let code = formatter. print_error ( & e, exit_code) ;
486449 USimpleError :: new ( code, "" )
0 commit comments