@@ -25,6 +25,7 @@ mod prn_float;
25
25
mod prn_int;
26
26
27
27
use std:: cmp;
28
+ use std:: collections:: HashMap ;
28
29
use std:: fmt:: Write ;
29
30
use std:: io:: BufReader ;
30
31
@@ -44,7 +45,7 @@ use clap::ArgAction;
44
45
use clap:: { Arg , ArgMatches , Command , parser:: ValueSource } ;
45
46
use uucore:: display:: Quotable ;
46
47
use uucore:: error:: { UResult , USimpleError } ;
47
- use uucore:: locale:: get_message;
48
+ use uucore:: locale:: { get_message, get_message_with_args } ;
48
49
use uucore:: parser:: parse_size:: ParseSizeError ;
49
50
use uucore:: parser:: shortcut_value_parser:: ShortcutValueParser ;
50
51
use uucore:: { format_usage, show_error, show_warning} ;
@@ -86,7 +87,10 @@ impl OdOptions {
86
87
_ => {
87
88
return Err ( USimpleError :: new (
88
89
1 ,
89
- format ! ( "Invalid argument --endian={s}" ) ,
90
+ get_message_with_args (
91
+ "od-error-invalid-endian" ,
92
+ HashMap :: from ( [ ( "endian" . to_string ( ) , s. to_string ( ) ) ] ) ,
93
+ ) ,
90
94
) ) ;
91
95
}
92
96
}
@@ -109,8 +113,15 @@ impl OdOptions {
109
113
110
114
let mut label: Option < u64 > = None ;
111
115
112
- let parsed_input = parse_inputs ( matches)
113
- . map_err ( |e| USimpleError :: new ( 1 , format ! ( "Invalid inputs: {e}" ) ) ) ?;
116
+ let parsed_input = parse_inputs ( matches) . map_err ( |e| {
117
+ USimpleError :: new (
118
+ 1 ,
119
+ get_message_with_args (
120
+ "od-error-invalid-inputs" ,
121
+ HashMap :: from ( [ ( "msg" . to_string ( ) , e. to_string ( ) ) ] ) ,
122
+ ) ,
123
+ )
124
+ } ) ?;
114
125
let input_strings = match parsed_input {
115
126
CommandLineInputs :: FileNames ( v) => v,
116
127
CommandLineInputs :: FileAndOffset ( ( f, s, l) ) => {
@@ -146,7 +157,16 @@ impl OdOptions {
146
157
cmp:: max ( max, next. formatter_item_info . byte_size )
147
158
} ) ;
148
159
if line_bytes == 0 || line_bytes % min_bytes != 0 {
149
- show_warning ! ( "invalid width {line_bytes}; using {min_bytes} instead" ) ;
160
+ show_warning ! (
161
+ "{}" ,
162
+ get_message_with_args(
163
+ "od-error-invalid-width" ,
164
+ HashMap :: from( [
165
+ ( "width" . to_string( ) , line_bytes. to_string( ) ) ,
166
+ ( "min" . to_string( ) , min_bytes. to_string( ) )
167
+ ] )
168
+ )
169
+ ) ;
150
170
line_bytes = min_bytes;
151
171
}
152
172
@@ -183,16 +203,16 @@ impl OdOptions {
183
203
_ => {
184
204
return Err ( USimpleError :: new (
185
205
1 ,
186
- "Radix must be one of [o, d, x, n]" . to_string ( ) ,
206
+ get_message_with_args (
207
+ "od-error-radix-invalid" ,
208
+ HashMap :: from ( [ ( "radix" . to_string ( ) , s. to_string ( ) ) ] ) ,
209
+ ) ,
187
210
) ) ;
188
211
}
189
212
}
190
213
} else {
191
214
// Return an error instead of panicking when `od -A ''` is executed.
192
- return Err ( USimpleError :: new (
193
- 1 ,
194
- "Radix cannot be empty, and must be one of [o, d, x, n]" . to_string ( ) ,
195
- ) ) ;
215
+ return Err ( USimpleError :: new ( 1 , get_message ( "od-error-radix-empty" ) ) ) ;
196
216
}
197
217
}
198
218
} ;
@@ -261,34 +281,34 @@ pub fn uu_app() -> Command {
261
281
. arg (
262
282
Arg :: new ( options:: HELP )
263
283
. long ( options:: HELP )
264
- . help ( "Print help information." )
284
+ . help ( get_message ( "od- help-help" ) )
265
285
. action ( ArgAction :: Help )
266
286
)
267
287
. arg (
268
288
Arg :: new ( options:: ADDRESS_RADIX )
269
289
. short ( 'A' )
270
290
. long ( options:: ADDRESS_RADIX )
271
- . help ( "Select the base in which file offsets are printed." )
291
+ . help ( get_message ( "od-help-address-radix" ) )
272
292
. value_name ( "RADIX" ) ,
273
293
)
274
294
. arg (
10000
275
295
Arg :: new ( options:: SKIP_BYTES )
276
296
. short ( 'j' )
277
297
. long ( options:: SKIP_BYTES )
278
- . help ( "Skip bytes input bytes before formatting and writing." )
298
+ . help ( get_message ( "od-help-skip- bytes" ) )
279
299
. value_name ( "BYTES" ) ,
280
300
)
281
301
. arg (
282
302
Arg :: new ( options:: READ_BYTES )
283
303
. short ( 'N' )
284
304
. long ( options:: READ_BYTES )
285
- . help ( "limit dump to BYTES input bytes")
305
+ . help ( get_message ( "od-help-read- bytes") )
286
306
. value_name ( "BYTES" ) ,
287
307
)
288
308
. arg (
289
309
Arg :: new ( options:: ENDIAN )
290
310
. long ( options:: ENDIAN )
291
- . help ( "byte order to use for multi-byte formats" )
311
+ . help ( get_message ( "od-help-endian" ) )
292
312
. value_parser ( ShortcutValueParser :: new ( [ "big" , "little" ] ) )
293
313
. value_name ( "big|little" ) ,
294
314
)
@@ -306,31 +326,31 @@ pub fn uu_app() -> Command {
306
326
. arg (
307
327
Arg :: new ( "a" )
308
328
. short ( 'a' )
309
- . help ( "named characters, ignoring high-order bit" )
329
+ . help ( get_message ( "od-help-a" ) )
310
330
. action ( ArgAction :: SetTrue ) ,
311
331
)
312
332
. arg (
313
333
Arg :: new ( "b" )
314
334
. short ( 'b' )
315
- . help ( "octal bytes" )
335
+ . help ( get_message ( "od-help-b" ) )
316
336
. action ( ArgAction :: SetTrue ) ,
317
337
)
318
338
. arg (
319
339
Arg :: new ( "c" )
320
340
. short ( 'c' )
321
- . help ( "ASCII characters or backslash escapes" )
341
+ . help ( get_message ( "od-help-c" ) )
322
342
. action ( ArgAction :: SetTrue ) ,
323
343
)
324
344
. arg (
325
345
Arg :: new ( "d" )
326
346
. short ( 'd' )
327
- . help ( "unsigned decimal 2-byte units" )
347
+ . help ( get_message ( "od-help-d" ) )
328
348
. action ( ArgAction :: SetTrue ) ,
329
349
)
330
350
. arg (
331
351
Arg :: new ( "D" )
332
352
. short ( 'D' )
333
- . help ( "unsigned decimal 4-byte units" )
353
+ . help ( get_message ( "od-help-D" ) )
334
354
. action ( ArgAction :: SetTrue ) ,
335
355
)
336
356
. arg (
@@ -421,7 +441,7 @@ pub fn uu_app() -> Command {
421
441
Arg :: new ( options:: FORMAT )
422
442
. short ( 't' )
423
443
. long ( "format" )
424
- . help ( "select output format or formats" )
444
+ . help ( get_message ( "od-help- format" ) )
425
445
. action ( ArgAction :: Append )
426
446
. num_args ( 1 )
427
447
. value_name ( "TYPE" ) ,
@@ -430,25 +450,22 @@ pub fn uu_app() -> Command {
430
450
Arg :: new ( options:: OUTPUT_DUPLICATES )
431
451
. short ( 'v' )
432
452
. long ( options:: OUTPUT_DUPLICATES )
433
- . help ( "do not use * to mark line suppression" )
453
+ . help ( get_message ( "od-help-output-duplicates" ) )
434
454
. action ( ArgAction :: SetTrue ) ,
435
455
)
436
456
. arg (
437
457
Arg :: new ( options:: WIDTH )
438
458
. short ( 'w' )
439
459
. long ( options:: WIDTH )
440
- . help (
441
- "output BYTES bytes per output line. 32 is implied when BYTES is not \
442
- specified.",
443
- )
460
+ . help ( get_message ( "od-help-width" ) )
444
461
. default_missing_value ( "32" )
445
462
. value_name ( "BYTES" )
446
463
. num_args ( ..=1 ) ,
447
464
)
448
465
. arg (
449
466
Arg :: new ( options:: TRADITIONAL )
450
467
. long ( options:: TRADITIONAL )
451
- . help ( "compatibility mode with one input, offset and label." )
468
+ . help ( get_message ( "od-help-traditional" ) )
452
469
. action ( ArgAction :: SetTrue ) ,
453
470
)
454
471
. arg (
@@ -631,12 +648,26 @@ fn format_error_message(error: &ParseSizeError, s: &str, option: &str) -> String
631
648
// NOTE:
632
649
// GNU's od echos affected flag, -N or --read-bytes (-j or --skip-bytes, etc.), depending user's selection
633
650
match error {
634
- ParseSizeError :: InvalidSuffix ( _) => {
635
- format ! ( "invalid suffix in --{option} argument {}" , s. quote( ) )
636
- }
637
- ParseSizeError :: ParseFailure ( _) | ParseSizeError :: PhysicalMem ( _) => {
638
- format ! ( "invalid --{option} argument {}" , s. quote( ) )
639
- }
640
- ParseSizeError :: SizeTooBig ( _) => format ! ( "--{option} argument {} too large" , s. quote( ) ) ,
651
+ ParseSizeError :: InvalidSuffix ( _) => get_message_with_args (
652
+ "od-error-invalid-suffix" ,
653
+ HashMap :: from ( [
654
+ ( "option" . to_string ( ) , option. to_string ( ) ) ,
655
+ ( "value" . to_string ( ) , s. quote ( ) . to_string ( ) ) ,
656
+ ] ) ,
657
+ ) ,
658
+ ParseSizeError :: ParseFailure ( _) | ParseSizeError :: PhysicalMem ( _) => get_message_with_args (
659
+ "od-error-invalid-argument" ,
660
+ HashMap :: from ( [
661
+ ( "option" . to_string ( ) , option. to_string ( ) ) ,
662
+ ( "value" . to_string ( ) , s. quote ( ) . to_string ( ) ) ,
663
+ ] ) ,
664
+ ) ,
665
+ ParseSizeError :: SizeTooBig ( _) => get_message_with_args (
666
+ "od-error-argument-too-large" ,
667
+ HashMap :: from ( [
668
+ ( "option" . to_string ( ) , option. to_string ( ) ) ,
669
+ ( "value" . to_string ( ) , s. quote ( ) . to_string ( ) ) ,
670
+ ] ) ,
671
+ ) ,
641
672
}
642
673
}
0 commit comments