6
6
// spell-checker:ignore (ToDO) clrtoeol dircolors eightbit endcode fnmatch leftcode multihardlink rightcode setenv sgid suid colorterm disp
7
7
8
8
use std:: borrow:: Borrow ;
9
+ use std:: collections:: HashMap ;
9
10
use std:: env;
10
11
use std:: fmt:: Write as _;
11
12
use std:: fs:: File ;
@@ -16,7 +17,7 @@ use clap::{Arg, ArgAction, Command};
16
17
use uucore:: colors:: { FILE_ATTRIBUTE_CODES , FILE_COLORS , FILE_TYPES , TERMS } ;
17
18
use uucore:: display:: Quotable ;
18
19
use uucore:: error:: { UResult , USimpleError , UUsageError } ;
19
- use uucore:: locale:: get_message;
20
+ use uucore:: locale:: { get_message, get_message_with_args } ;
20
21
use uucore:: { format_usage, parser:: parse_glob} ;
21
22
22
23
mod options {
@@ -132,26 +133,24 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
132
133
{
133
134
return Err ( UUsageError :: new (
134
135
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" ) ,
137
137
) ) ;
138
138
}
139
139
140
140
if matches. get_flag ( options:: PRINT_DATABASE ) && matches. get_flag ( options:: PRINT_LS_COLORS ) {
141
141
return Err ( UUsageError :: new (
142
142
1 ,
143
- "options - -print-database and --print- ls-colors are mutually exclusive",
143
+ get_message ( "dircolors-error -print-database- and- ls-colors- exclusive") ,
144
144
) ) ;
145
145
}
146
146
147
147
if matches. get_flag ( options:: PRINT_DATABASE ) {
148
148
if !files. is_empty ( ) {
149
149
return Err ( UUsageError :: new (
150
150
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 ( ) ) ] ) ,
155
154
) ,
156
155
) ) ;
157
156
}
@@ -175,7 +174,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
175
174
OutputFmt :: Unknown => {
176
175
return Err ( USimpleError :: new (
177
176
1 ,
178
- "no SHELL environment variable, and no shell type option given" ,
177
+ get_message ( "dircolors-error-no- shell-environment" ) ,
179
178
) ) ;
180
179
}
181
180
fmt => out_format = fmt,
@@ -201,7 +200,10 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
201
200
} else if files. len ( ) > 1 {
202
201
return Err ( UUsageError :: new (
203
202
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
+ ) ,
205
207
) ) ;
206
208
} else if files[ 0 ] . eq ( "-" ) {
207
209
let fin = BufReader :: new ( std:: io:: stdin ( ) ) ;
@@ -212,7 +214,10 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
212
214
if path. is_dir ( ) {
213
215
return Err ( USimpleError :: new (
214
216
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
+ ) ,
216
221
) ) ;
217
222
}
218
223
match File :: open ( path) {
@@ -253,7 +258,7 @@ pub fn uu_app() -> Command {
253
258
. short ( 'b' )
254
259
. visible_alias ( "bourne-shell" )
255
260
. overrides_with ( options:: C_SHELL )
256
- . help ( "output Bourne shell code to set LS_COLORS" )
261
+ . help ( get_message ( "dircolors-help-bourne- shell" ) )
257
262
. action ( ArgAction :: SetTrue ) ,
258
263
)
259
264
. arg (
@@ -262,20 +267,20 @@ pub fn uu_app() -> Command {
262
267
. short ( 'c' )
263
268
. visible_alias ( "c-shell" )
264
269
. overrides_with ( options:: BOURNE_SHELL )
265
- . help ( "output C shell code to set LS_COLORS" )
270
+ . help ( get_message ( "dircolors-help-c- shell" ) )
266
271
. action ( ArgAction :: SetTrue ) ,
267
272
)
268
273
. arg (
269
274
Arg :: new ( options:: PRINT_DATABASE )
270
275
. long ( "print-database" )
271
276
. short ( 'p' )
272
- . help ( " print the byte counts" )
277
+ . help ( get_message ( "dircolors-help- print-database" ) )
273
278
. action ( ArgAction :: SetTrue ) ,
274
279
)
275
280
. arg (
276
281
Arg :: new ( options:: PRINT_LS_COLORS )
277
282
. long ( "print-ls-colors" )
278
- . help ( "output fully escaped colors for display" )
283
+ . help ( get_message ( "dircolors-help-print-ls- colors" ) )
279
284
. action ( ArgAction :: SetTrue ) ,
280
285
)
281
286
. arg (
@@ -375,10 +380,12 @@ where
375
380
376
381
let ( key, val) = line. split_two ( ) ;
377
382
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
+ ] ) ,
382
389
) ) ;
383
390
}
384
391
@@ -461,7 +468,10 @@ fn append_entry(
461
468
result. push_str ( & disp) ;
462
469
Ok ( ( ) )
463
470
} 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
+ ) )
465
475
}
466
476
}
467
477
}
0 commit comments