@@ -207,7 +207,11 @@ impl TryFrom<SudoOptions> for SudoValidateOptions {
207207 let user = mem:: take ( & mut opts. user ) ;
208208
209209 if bell && stdin {
210- return Err ( "--bell conflicts with --stdin" . into ( ) ) ;
210+ return Err ( xlat ! (
211+ "{option1} conflicts with {option2}" ,
212+ option1 = "--bell" ,
213+ option2 = "--stdin"
214+ ) ) ;
211215 }
212216
213217 reject_all ( "--validate" , opts) ?;
@@ -268,13 +272,17 @@ impl TryFrom<SudoOptions> for SudoEditOptions {
268272 let positional_args = mem:: take ( & mut opts. positional_args ) ;
269273
270274 if bell && stdin {
271- return Err ( "--bell conflicts with --stdin" . into ( ) ) ;
275+ return Err ( xlat ! (
276+ "{option1} conflicts with {option2}" ,
277+ option1 = "--bell" ,
278+ option2 = "--stdin"
279+ ) ) ;
272280 }
273281
274282 reject_all ( "--edit" , opts) ?;
275283
276284 if positional_args. is_empty ( ) {
277- return Err ( "must specify at least one file path" . into ( ) ) ;
285+ return Err ( xlat ! ( "must specify at least one file path" ) . into ( ) ) ;
278286 }
279287
280288 Ok ( Self {
@@ -336,15 +344,22 @@ impl TryFrom<SudoOptions> for SudoListOptions {
336344 let positional_args = mem:: take ( & mut opts. positional_args ) ;
337345
338346 if bell && stdin {
339- return Err ( "--bell conflicts with --stdin" . into ( ) ) ;
347+ return Err ( xlat ! (
348+ "{option1} conflicts with {option2}" ,
349+ option1 = "--bell" ,
350+ option2 = "--stdin"
351+ ) ) ;
340352 }
341353
342354 // when present, `-u` must be accompanied by a command
343355 let has_command = !positional_args. is_empty ( ) ;
344356 let valid_user_flag = user. is_none ( ) || has_command;
345357
346358 if !valid_user_flag {
347- return Err ( "'--user' flag must be accompanied by a command" . into ( ) ) ;
359+ return Err ( xlat ! (
360+ "'{option}' flag must be accompanied by a command" ,
361+ option = "--user"
362+ ) ) ;
348363 }
349364
350365 reject_all ( "--list" , opts) ?;
@@ -415,24 +430,34 @@ impl TryFrom<SudoOptions> for SudoRunOptions {
415430 let positional_args = mem:: take ( & mut opts. positional_args ) ;
416431
417432 if bell && stdin {
418- return Err ( "--bell conflicts with --stdin" . into ( ) ) ;
433+ return Err ( xlat ! (
434+ "{option1} conflicts with {option2}" ,
435+ option1 = "--bell" ,
436+ option2 = "--stdin"
437+ ) ) ;
419438 }
420439
421440 let context = match ( login, shell, positional_args. is_empty ( ) ) {
422441 ( true , false , _) => "--login" ,
423442 ( false , true , _) => "--shell" ,
424- ( false , false , false ) => "command (positional argument)" ,
425-
426- ( true , true , _) => return Err ( "--login conflicts with --shell" . into ( ) ) ,
443+ ( false , false , false ) => xlat ! ( "command (positional argument)" ) ,
444+
445+ ( true , true , _) => {
446+ return Err ( xlat ! (
447+ "{option1} conflicts with {option2}" ,
448+ option1 = "--login" ,
449+ option2 = "--shell"
450+ ) )
451+ }
427452 ( false , false , true ) => {
428453 if cfg ! ( debug_assertions) {
429454 // see `SudoOptions::validate`
430455 panic ! ( ) ;
431456 } else {
432- return Err (
457+ return Err ( xlat ! (
433458 "expected one of: --login, --shell, a command as a positional argument"
434- . into ( ) ,
435- ) ;
459+ )
460+ . into ( ) ) ;
436461 }
437462 }
438463 } ;
@@ -586,7 +611,7 @@ impl SudoArg {
586611
587612 // assignment syntax is not accepted for shorthand arguments
588613 if next == Some ( '=' ) {
589- Err ( "invalid option '='" ) ?;
614+ Err ( xlat ! ( "invalid option '='" ) ) ?;
590615 }
591616 if next. is_some ( ) {
592617 processed. push ( SudoArg :: Argument ( flag, rest. to_string ( ) ) ) ;
@@ -596,7 +621,7 @@ impl SudoArg {
596621 // short version of --help has no arguments
597622 processed. push ( SudoArg :: Flag ( flag) ) ;
598623 } else {
599- Err ( xlat ! ( "'- {option}' expects an argument" , option = curr ) ) ?;
624+ Err ( xlat ! ( "'{option}' expects an argument" , option = flag ) ) ?;
600625 }
601626 break ;
602627 } else {
@@ -639,7 +664,7 @@ impl SudoOptions {
639664 } else if self . reset_timestamp {
640665 SudoAction :: ResetTimestamp ( self . try_into ( ) ?)
641666 } else {
642- return Err ( "expected one of these actions: --help, --version, --remove-timestamp, --validate, --list, --edit, --login, --shell, a command as a positional argument, --reset-timestamp" . into ( ) ) ;
667+ return Err ( xlat ! ( "expected one of these actions: --help, --version, --remove-timestamp, --validate, --list, --edit, --login, --shell, a command as a positional argument, --reset-timestamp" ) . into ( ) ) ;
643668 }
644669 } ;
645670
@@ -720,7 +745,7 @@ impl SudoOptions {
720745 options. validate = true ;
721746 }
722747 _option => {
723- Err ( "invalid option provided" ) ?;
748+ Err ( xlat ! ( "invalid option provided" ) ) ?;
724749 }
725750 } ,
726751 SudoArg :: Argument ( option, value) => match option. as_str ( ) {
@@ -749,7 +774,7 @@ impl SudoOptions {
749774 options. user = Some ( SudoString :: from_cli_string ( value) ) ;
750775 }
751776 _option => {
752- Err ( "invalid option provided" ) ?;
777+ Err ( xlat ! ( "invalid option provided" ) ) ?;
753778 }
754779 } ,
755780 SudoArg :: Environment ( key, value) => {
@@ -828,7 +853,7 @@ fn ensure_is_absent(context: &str, thing: &dyn IsAbsent, name: &str) -> Result<(
828853
829854fn reject_all ( context : & str , opts : SudoOptions ) -> Result < ( ) , String > {
830855 macro_rules! check_options {
831- ( $( $field: ident $( = $name: literal ) ?, ) * ) => { {
856+ ( $( $field: ident $( = $name: expr ) ?, ) * ) => { {
832857 let SudoOptions { $( $field) ,* } = opts;
833858
834859 $(
@@ -846,7 +871,7 @@ fn reject_all(context: &str, opts: SudoOptions) -> Result<(), String> {
846871 Cow :: Borrowed ( name)
847872 }
848873 } } ;
849- ( @name $field: ident $name: literal ) => {
874+ ( @name $field: ident $name: expr ) => {
850875 $name
851876 } ;
852877 }
@@ -870,7 +895,7 @@ fn reject_all(context: &str, opts: SudoOptions) -> Result<(), String> {
870895 user,
871896 validate,
872897 version,
873- positional_args = "command" ,
874- env_var_list = "environment variable" ,
898+ positional_args = xlat! ( "command" ) ,
899+ env_var_list = xlat! ( "environment variable" ) ,
875900 )
876901}
0 commit comments