66// spell-checker:ignore (ToDO) clrtoeol dircolors eightbit endcode fnmatch leftcode multihardlink rightcode setenv sgid suid colorterm disp
77
88use std:: borrow:: Borrow ;
9+ use std:: collections:: HashMap ;
910use std:: env;
1011use std:: fmt:: Write as _;
1112use std:: fs:: File ;
@@ -16,7 +17,7 @@ use clap::{Arg, ArgAction, Command};
1617use uucore:: colors:: { FILE_ATTRIBUTE_CODES , FILE_COLORS , FILE_TYPES , TERMS } ;
1718use uucore:: display:: Quotable ;
1819use uucore:: error:: { UResult , USimpleError , UUsageError } ;
19- use uucore:: locale:: get_message;
20+ use uucore:: locale:: { get_message, get_message_with_args } ;
2021use uucore:: { format_usage, parser:: parse_glob} ;
2122
2223mod options {
@@ -132,26 +133,24 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
132133 {
133134 return Err ( UUsageError :: new (
134135 1 ,
135- "the options to output non shell syntax,\n \
136- and to select a shell syntax are mutually exclusive",
136+ get_message ( "dircolors-error-shell-and-output-exclusive" ) ,
137137 ) ) ;
138138 }
139139
140140 if matches. get_flag ( options:: PRINT_DATABASE ) && matches. get_flag ( options:: PRINT_LS_COLORS ) {
141141 return Err ( UUsageError :: new (
142142 1 ,
143- "options - -print-database and --print- ls-colors are mutually exclusive",
143+ get_message ( "dircolors-error -print-database- and- ls-colors- exclusive") ,
144144 ) ) ;
145145 }
146146
147147 if matches. get_flag ( options:: PRINT_DATABASE ) {
148148 if !files. is_empty ( ) {
149149 return Err ( UUsageError :: new (
150150 1 ,
151- format ! (
152- "extra operand {}\n file operands cannot be combined with \
153- --print-database (-p)",
154- files[ 0 ] . quote( )
151+ get_message_with_args (
152+ "dircolors-error-extra-operand-print-database" ,
153+ HashMap :: from ( [ ( "operand" . to_string ( ) , files[ 0 ] . quote ( ) . to_string ( ) ) ] ) ,
155154 ) ,
156155 ) ) ;
157156 }
@@ -175,7 +174,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
175174 OutputFmt :: Unknown => {
176175 return Err ( USimpleError :: new (
177176 1 ,
178- "no SHELL environment variable, and no shell type option given" ,
177+ get_message ( "dircolors-error-no- shell-environment" ) ,
179178 ) ) ;
180179 }
181180 fmt => out_format = fmt,
@@ -201,7 +200,10 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
201200 } else if files. len ( ) > 1 {
202201 return Err ( UUsageError :: new (
203202 1 ,
204- format ! ( "extra operand {}" , files[ 1 ] . quote( ) ) ,
203+ get_message_with_args (
204+ "dircolors-error-extra-operand" ,
205+ HashMap :: from ( [ ( "operand" . to_string ( ) , files[ 1 ] . quote ( ) . to_string ( ) ) ] ) ,
206+ ) ,
205207 ) ) ;
206208 } else if files[ 0 ] . eq ( "-" ) {
207209 let fin = BufReader :: new ( std:: io:: stdin ( ) ) ;
@@ -212,7 +214,10 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
212214 if path. is_dir ( ) {
213215 return Err ( USimpleError :: new (
214216 2 ,
215- format ! ( "expected file, got directory {}" , path. quote( ) ) ,
217+ get_message_with_args (
218+ "dircolors-error-expected-file-got-directory" ,
219+ HashMap :: from ( [ ( "path" . to_string ( ) , path. quote ( ) . to_string ( ) ) ] ) ,
220+ ) ,
216221 ) ) ;
217222 }
218223 match File :: open ( path) {
@@ -253,7 +258,7 @@ pub fn uu_app() -> Command {
253258 . short ( 'b' )
254259 . visible_alias ( "bourne-shell" )
255260 . overrides_with ( options:: C_SHELL )
256- . help ( "output Bourne shell code to set LS_COLORS" )
261+ . help ( get_message ( "dircolors-help-bourne- shell" ) )
257262 . action ( ArgAction :: SetTrue ) ,
258263 )
259264 . arg (
@@ -262,20 +267,20 @@ pub fn uu_app() -> Command {
262267 . short ( 'c' )
263268 . visible_alias ( "c-shell" )
264269 . overrides_with ( options:: BOURNE_SHELL )
265- . help ( "output C shell code to set LS_COLORS" )
270+ . help ( get_message ( "dircolors-help-c- shell" ) )
266271 . action ( ArgAction :: SetTrue ) ,
267272 )
268273 . arg (
269274 Arg :: new ( options:: PRINT_DATABASE )
270275 . long ( "print-database" )
271276 . short ( 'p' )
272- . help ( " print the byte counts" )
277+ . help ( get_message ( "dircolors-help- print-database" ) )
273278 . action ( ArgAction :: SetTrue ) ,
274279 )
275280 . arg (
276281 Arg :: new ( options:: PRINT_LS_COLORS )
277282 . long ( "print-ls-colors" )
278- . help ( "output fully escaped colors for display" )
283+ . help ( get_message ( "dircolors-help-print-ls- colors" ) )
279284 . action ( ArgAction :: SetTrue ) ,
280285 )
281286 . arg (
@@ -375,10 +380,12 @@ where
375380
376381 let ( key, val) = line. split_two ( ) ;
377382 if val. is_empty ( ) {
378- return Err ( format ! (
379- // The double space is what GNU is doing
380- "{}:{num}: invalid line; missing second token" ,
381- fp. maybe_quote( ) ,
383+ return Err ( get_message_with_args (
384+ "dircolors-error-invalid-line-missing-token" ,
385+ HashMap :: from ( [
386+ ( "file" . to_string ( ) , fp. maybe_quote ( ) . to_string ( ) ) ,
387+ ( "line" . to_string ( ) , num. to_string ( ) ) ,
388+ ] ) ,
382389 ) ) ;
383390 }
384391
@@ -461,7 +468,10 @@ fn append_entry(
461468 result. push_str ( & disp) ;
462469 Ok ( ( ) )
463470 } else {
464- Err ( format ! ( "unrecognized keyword {key}" ) )
471+ Err ( get_message_with_args (
472+ "dircolors-error-unrecognized-keyword" ,
473+ HashMap :: from ( [ ( "keyword" . to_string ( ) , key. to_string ( ) ) ] ) ,
474+ ) )
465475 }
466476 }
467477 }
0 commit comments