@@ -29,7 +29,8 @@ use crate::filesystem::Filesystem;
29
29
use crate :: filesystem:: FsError ;
30
30
use crate :: table:: Table ;
31
31
32
- use uucore:: locale:: get_message;
32
+ use std:: collections:: HashMap ;
33
+ use uucore:: locale:: { get_message, get_message_with_args} ;
33
34
34
35
static OPT_HELP : & str = "help" ;
35
36
static OPT_ALL : & str = "all" ;
@@ -115,25 +116,28 @@ impl Default for Options {
115
116
enum OptionsError {
116
117
// TODO This needs to vary based on whether `--block-size`
117
118
// or `-B` were provided.
118
- #[ error( "- -block-size argument '{0}' too large" ) ]
119
+ #[ error( "{}" , get_message_with_args ( "df-error -block-size- too- large", HashMap :: from ( [ ( "size" . to_string ( ) , . 0 . clone ( ) ) ] ) ) ) ]
119
120
BlockSizeTooLarge ( String ) ,
120
121
// TODO This needs to vary based on whether `--block-size`
121
122
// or `-B` were provided.,
122
- #[ error( "invalid -- block-size argument {0}" ) ]
123
+ #[ error( "{}" , get_message_with_args ( "df-error-invalid- block-size" , HashMap :: from ( [ ( "size" . to_string ( ) , . 0 . clone ( ) ) ] ) ) ) ]
123
124
InvalidBlockSize ( String ) ,
124
125
// TODO This needs to vary based on whether `--block-size`
125
126
// or `-B` were provided.
126
- #[ error( "invalid suffix in --block- size argument {0}" ) ]
127
+ #[ error( "{}" , get_message_with_args ( "df-error-invalid-suffix" , HashMap :: from ( [ ( " size" . to_string ( ) , . 0 . clone ( ) ) ] ) ) ) ]
127
128
InvalidSuffix ( String ) ,
128
129
129
130
/// An error getting the columns to display in the output table.
130
- #[ error( "option --output: field {0} used more than once" ) ]
131
+ #[ error( "{}" , get_message_with_args ( "df-error- field- used- more- than- once", HashMap :: from ( [ ( "field" . to_string ( ) , format! ( "{}" , . 0 ) ) ] ) ) ) ]
131
132
ColumnError ( ColumnError ) ,
132
133
133
- #[ error( "{}" , . 0 . iter( )
134
- . map( |t| format!( "file system type {} both selected and excluded" , t. quote( ) ) )
134
+ #[ error(
135
+ "{}" ,
136
+ . 0 . iter( )
137
+ . map( |t| get_message_with_args( "df-error-filesystem-type-both-selected-and-excluded" , HashMap :: from( [ ( "type" . to_string( ) , t. quote( ) . to_string( ) ) ] ) ) )
135
138
. collect:: <Vec <_>>( )
136
- . join( format!( "\n {}: " , uucore:: util_name( ) ) . as_str( ) ) ) ]
139
+ . join( format!( "\n {}: " , uucore:: util_name( ) ) . as_str( ) )
140
+ ) ]
137
141
FilesystemTypeBothSelectedAndExcluded ( Vec < String > ) ,
138
142
}
139
143
@@ -359,26 +363,35 @@ where
359
363
Err ( FsError :: InvalidPath ) => {
360
364
show ! ( USimpleError :: new(
361
365
1 ,
362
- format!( "{}: No such file or directory" , path. as_ref( ) . display( ) )
366
+ get_message_with_args(
367
+ "df-error-no-such-file-or-directory" ,
368
+ HashMap :: from( [ ( "path" . to_string( ) , path. as_ref( ) . display( ) . to_string( ) ) ] )
369
+ )
363
370
) ) ;
364
371
}
365
372
Err ( FsError :: MountMissing ) => {
366
- show ! ( USimpleError :: new( 1 , "no file systems processed" ) ) ;
373
+ show ! ( USimpleError :: new(
374
+ 1 ,
375
+ get_message( "df-error-no-file-systems-processed" )
376
+ ) ) ;
367
377
}
368
378
#[ cfg( not( windows) ) ]
369
379
Err ( FsError :: OverMounted ) => {
370
380
show ! ( USimpleError :: new(
371
381
1 ,
372
- format! (
373
- "cannot access {}: over-mounted by another device " ,
374
- path. as_ref( ) . quote( )
382
+ get_message_with_args (
383
+ "df-error- cannot- access- over-mounted" ,
384
+ HashMap :: from ( [ ( " path" . to_string ( ) , path . as_ref( ) . quote( ) . to_string ( ) ) ] )
375
385
)
376
386
) ) ;
377
387
}
378
388
}
379
389
}
380
390
if get_exit_code ( ) == 0 && result. is_empty ( ) {
381
- show ! ( USimpleError :: new( 1 , "no file systems processed" ) ) ;
391
+ show ! ( USimpleError :: new(
392
+ 1 ,
393
+ get_message( "df-error-no-file-systems-processed" )
394
+ ) ) ;
382
395
return Ok ( result) ;
383
396
}
384
397
@@ -405,7 +418,13 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
405
418
#[ cfg( windows) ]
406
419
{
407
420
if matches. get_flag ( OPT_INODES ) {
408
- println ! ( "{}: doesn't support -i option" , uucore:: util_name( ) ) ;
421
+ println ! (
422
+ "{}" ,
423
+ get_message_with_args(
424
+ "df-error-inodes-not-supported-windows" ,
425
+ HashMap :: from( [ ( "program" . to_string( ) , uucore:: util_name( ) . to_string( ) ) ] )
426
+ )
427
+ ) ;
409
428
return Ok ( ( ) ) ;
410
429
}
411
430
}
@@ -415,20 +434,23 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
415
434
let filesystems: Vec < Filesystem > = match matches. get_many :: < String > ( OPT_PATHS ) {
416
435
None => {
417
436
let filesystems = get_all_filesystems ( & opt) . map_err ( |e| {
418
- let context = " cannot read table of mounted file systems" ;
437
+ let context = get_message ( "df-error- cannot- read- table-of- mounted-filesystems" ) ;
419
438
USimpleError :: new ( e. code ( ) , format ! ( "{context}: {e}" ) )
420
439
} ) ?;
421
440
422
441
if filesystems. is_empty ( ) {
423
- return Err ( USimpleError :: new ( 1 , "no file systems processed" ) ) ;
442
+ return Err ( USimpleError :: new (
443
+ 1 ,
444
+ get_message ( "df-error-no-file-systems-processed" ) ,
445
+ ) ) ;
424
446
}
425
447
426
448
filesystems
427
449
}
428
450
Some ( paths) => {
429
451
let paths: Vec < _ > = paths. collect ( ) ;
430
452
let filesystems = get_named_filesystems ( & paths, & opt) . map_err ( |e| {
431
- let context = " cannot read table of mounted file systems" ;
453
+ let context = get_message ( "df-error- cannot- read- table-of- mounted-filesystems" ) ;
432
454
USimpleError :: new ( e. code ( ) , format ! ( "{context}: {e}" ) )
433
455
} ) ?;
434
456
@@ -458,15 +480,15 @@ pub fn uu_app() -> Command {
458
480
. arg (
459
481
Arg :: new ( OPT_HELP )
460
482
. long ( OPT_HELP )
461
- . help ( "Print help information." )
483
+ . help ( get_message ( "df- help-print-help" ) )
462
484
. action ( ArgAction :: Help ) ,
463
485
)
464
486
. arg (
465
487
Arg :: new ( OPT_ALL )
466
488
. short ( 'a' )
467
489
. long ( "all" )
468
490
. overrides_with ( OPT_ALL )
469
- . help ( "include dummy file systems" )
491
+ . help ( get_message ( "df-help-all" ) )
470
492
. action ( ArgAction :: SetTrue ) ,
471
493
)
472
494
. arg (
@@ -475,46 +497,43 @@ pub fn uu_app() -> Command {
475
497
. long ( "block-size" )
476
498
. value_name ( "SIZE" )
477
499
. overrides_with_all ( [ OPT_KILO , OPT_BLOCKSIZE ] )
478
- . help (
479
- "scale sizes by SIZE before printing them; e.g.\
480
- '-BM' prints sizes in units of 1,048,576 bytes",
481
- ) ,
500
+ . help ( get_message ( "df-help-block-size" ) ) ,
482
501
)
483
502
. arg (
484
503
Arg :: new ( OPT_TOTAL )
485
504
. long ( "total" )
486
505
. overrides_with ( OPT_TOTAL )
487
- . help ( "produce a grand total")
506
+ . help ( get_message ( "df-help- total") )
488
507
. action ( ArgAction :: SetTrue ) ,
489
508
)
490
509
. arg (
491
510
Arg :: new ( OPT_HUMAN_READABLE_BINARY )
492
511
. short ( 'h' )
493
512
. long ( "human-readable" )
494
513
. overrides_with_all ( [ OPT_HUMAN_READABLE_DECIMAL , OPT_HUMAN_READABLE_BINARY ] )
495
- . help ( "print sizes in human readable format (e.g., 1K 234M 2G)" )
514
+ . help ( get_message ( "df-help- human- readable" ) )
496
515
. action ( ArgAction :: SetTrue ) ,
497
516
)
498
517
. arg (
499
518
Arg :: new ( OPT_HUMAN_READABLE_DECIMAL )
500
519
. short ( 'H' )
501
520
. long ( "si" )
502
521
. overrides_with_all ( [ OPT_HUMAN_READABLE_BINARY , OPT_HUMAN_READABLE_DECIMAL ] )
503
- . help ( "likewise, but use powers of 1000 not 1024" )
522
+ . help ( get_message ( "df-help-si" ) )
504
523
. action ( ArgAction :: SetTrue ) ,
505
524
)
506
525
. arg (
507
526
Arg :: new ( OPT_INODES )
508
527
. short ( 'i' )
509
528
. long ( "inodes" )
510
529
. overrides_with ( OPT_INODES )
511
- . help ( "list inode information instead of block usage" )
530
+ . help ( get_message ( "df-help-inodes" ) )
512
531
. action ( ArgAction :: SetTrue ) ,
513
532
)
514
533
. arg (
515
534
Arg :: new ( OPT_KILO )
516
535
. short ( 'k' )
517
- . help ( "like --block-size=1K" )
536
+ . help ( get_message ( "df-help-kilo" ) )
518
537
. overrides_with_all ( [ OPT_BLOCKSIZE , OPT_KILO ] )
519
538
. action ( ArgAction :: SetTrue ) ,
520
539
)
@@ -523,14 +542,14 @@ pub fn uu_app() -> Command {
523
542
. short ( 'l' )
524
543
. long ( "local" )
525
544
. overrides_with ( OPT_LOCAL )
526
- . help ( "limit listing to local file systems" )
545
+ . help ( get_message ( "df-help- local" ) )
527
546
. action ( ArgAction :: SetTrue ) ,
528
547
)
529
548
. arg (
530
549
Arg :: new ( OPT_NO_SYNC )
531
550
. long ( "no-sync" )
532
551
. overrides_with_all ( [ OPT_SYNC , OPT_NO_SYNC ] )
533
- . help ( "do not invoke sync before getting usage info (default)" )
552
+ . help ( get_message ( "df-help-no- sync" ) )
534
553
. action ( ArgAction :: SetTrue ) ,
535
554
)
536
555
. arg (
@@ -545,24 +564,21 @@ pub fn uu_app() -> Command {
545
564
. default_missing_values ( OUTPUT_FIELD_LIST )
546
565
. default_values ( [ "source" , "size" , "used" , "avail" , "pcent" , "target" ] )
547
566
. conflicts_with_all ( [ OPT_INODES , OPT_PORTABILITY , OPT_PRINT_TYPE ] )
548
- . help (
549
- "use the output format defined by FIELD_LIST, \
550
- or print all fields if FIELD_LIST is omitted.",
551
- ) ,
567
+ . help ( get_message ( "df-help-output" ) ) ,
552
568
)
553
569
. arg (
554
570
Arg :: new ( OPT_PORTABILITY )
555
571
. short ( 'P' )
556
572
. long ( "portability" )
557
573
. overrides_with ( OPT_PORTABILITY )
558
- . help ( "use the POSIX output format" )
574
+ . help ( get_message ( "df-help-portability" ) )
559
575
. action ( ArgAction :: SetTrue ) ,
560
576
)
561
577
. arg (
562
578
Arg :: new ( OPT_SYNC )
563
579
. long ( "sync" )
564
580
. overrides_with_all ( [ OPT_NO_SYNC , OPT_SYNC ] )
565
- . help ( "invoke sync before getting usage info (non-windows only)" )
581
+ . help ( get_message ( "df-help-sync" ) )
566
582
. action ( ArgAction :: SetTrue ) ,
567
583
)
568
584
. arg (
@@ -572,14 +588,14 @@ pub fn uu_app() -> Command {
572
588
. value_parser ( ValueParser :: os_string ( ) )
573
589
. value_name ( "TYPE" )
574
590
. action ( ArgAction :: Append )
575
- . help ( "limit listing to file systems of type TYPE" ) ,
591
+ . help ( get_message ( "df-help- type" ) ) ,
576
592
)
577
593
. arg (
578
594
Arg :: new ( OPT_PRINT_TYPE )
579
595
. short ( 'T' )
580
596
. long ( "print-type" )
581
597
. overrides_with ( OPT_PRINT_TYPE )
582
- . help ( " print file system type")
598
+ . help ( get_message ( "df-help- print- type") )
583
599
. action ( ArgAction :: SetTrue ) ,
584
600
)
585
601
. arg (
@@ -590,7 +606,7 @@ pub fn uu_app() -> Command {
590
606
. value_parser ( ValueParser :: os_string ( ) )
591
607
. value_name ( "TYPE" )
592
608
. use_value_delimiter ( true )
593
- . help ( "limit listing to file systems not of type TYPE" ) ,
609
+ . help ( get_message ( "df-help-exclude- type" ) ) ,
594
610
)
595
611
. arg (
596
612
Arg :: new ( OPT_PATHS )
0 commit comments