@@ -14,6 +14,7 @@ pub enum Format {
14
14
15
15
#[ derive( Clone , Debug , Eq , PartialEq ) ]
16
16
pub struct Params {
17
+ pub executable : OsString ,
17
18
pub from : OsString ,
18
19
pub to : OsString ,
19
20
pub format : Format ,
@@ -27,6 +28,7 @@ pub struct Params {
27
28
impl Default for Params {
28
29
fn default ( ) -> Self {
29
30
Self {
31
+ executable : OsString :: default ( ) ,
30
32
from : OsString :: default ( ) ,
31
33
to : OsString :: default ( ) ,
32
34
format : Format :: default ( ) ,
@@ -43,10 +45,13 @@ pub fn parse_params<I: IntoIterator<Item = OsString>>(opts: I) -> Result<Params,
43
45
let mut opts = opts. into_iter ( ) . peekable ( ) ;
44
46
// parse CLI
45
47
46
- let Some ( exe ) = opts. next ( ) else {
48
+ let Some ( executable ) = opts. next ( ) else {
47
49
return Err ( "Usage: <exe> <from> <to>" . to_string ( ) ) ;
48
50
} ;
49
- let mut params = Params :: default ( ) ;
51
+ let mut params = Params {
52
+ executable,
53
+ ..Default :: default ( )
54
+ } ;
50
55
let mut from = None ;
51
56
let mut to = None ;
52
57
let mut format = None ;
@@ -63,7 +68,10 @@ pub fn parse_params<I: IntoIterator<Item = OsString>>(opts: I) -> Result<Params,
63
68
} else if to. is_none ( ) {
64
69
to = Some ( param) ;
65
70
} else {
66
- return Err ( format ! ( "Usage: {} <from> <to>" , exe. to_string_lossy( ) ) ) ;
71
+ return Err ( format ! (
72
+ "Usage: {} <from> <to>" ,
73
+ params. executable. to_string_lossy( )
74
+ ) ) ;
67
75
}
68
76
continue ;
69
77
}
@@ -155,22 +163,31 @@ pub fn parse_params<I: IntoIterator<Item = OsString>>(opts: I) -> Result<Params,
155
163
} else if to. is_none ( ) {
156
164
to = Some ( param) ;
157
165
} else {
158
- return Err ( format ! ( "Usage: {} <from> <to>" , exe. to_string_lossy( ) ) ) ;
166
+ return Err ( format ! (
167
+ "Usage: {} <from> <to>" ,
168
+ params. executable. to_string_lossy( )
169
+ ) ) ;
159
170
}
160
171
}
161
172
params. from = if let Some ( from) = from {
162
173
from
163
174
} else if let Some ( param) = opts. next ( ) {
164
175
param
165
176
} else {
166
- return Err ( format ! ( "Usage: {} <from> <to>" , exe. to_string_lossy( ) ) ) ;
177
+ return Err ( format ! (
178
+ "Usage: {} <from> <to>" ,
179
+ params. executable. to_string_lossy( )
180
+ ) ) ;
167
181
} ;
168
182
params. to = if let Some ( to) = to {
169
183
to
170
184
} else if let Some ( param) = opts. next ( ) {
171
185
param
172
186
} else {
173
- return Err ( format ! ( "Usage: {} <from> <to>" , exe. to_string_lossy( ) ) ) ;
187
+ return Err ( format ! (
188
+ "Usage: {} <from> <to>" ,
189
+ params. executable. to_string_lossy( )
190
+ ) ) ;
174
191
} ;
175
192
176
193
// diff DIRECTORY FILE => diff DIRECTORY/FILE FILE
@@ -301,6 +318,7 @@ mod tests {
301
318
fn basics ( ) {
302
319
assert_eq ! (
303
320
Ok ( Params {
321
+ executable: os( "diff" ) ,
304
322
from: os( "foo" ) ,
305
323
to: os( "bar" ) ,
306
324
..Default :: default ( )
@@ -309,6 +327,7 @@ mod tests {
309
327
) ;
310
328
assert_eq ! (
311
329
Ok ( Params {
330
+ executable: os( "diff" ) ,
312
331
from: os( "foo" ) ,
313
332
to: os( "bar" ) ,
314
333
..Default :: default ( )
@@ -325,6 +344,7 @@ mod tests {
325
344
for arg in [ "-e" , "--ed" ] {
326
345
assert_eq ! (
327
346
Ok ( Params {
347
+ executable: os( "diff" ) ,
328
348
from: os( "foo" ) ,
329
349
to: os( "bar" ) ,
330
350
format: Format :: Ed ,
@@ -342,6 +362,7 @@ mod tests {
342
362
params. extend ( [ "foo" , "bar" ] ) ;
343
363
assert_eq ! (
344
364
Ok ( Params {
365
+ executable: os( "diff" ) ,
345
366
from: os( "foo" ) ,
346
367
to: os( "bar" ) ,
347
368
format: Format :: Context ,
@@ -362,6 +383,7 @@ mod tests {
362
383
params. extend ( [ "foo" , "bar" ] ) ;
363
384
assert_eq ! (
364
385
Ok ( Params {
386
+ executable: os( "diff" ) ,
365
387
from: os( "foo" ) ,
366
388
to: os( "bar" ) ,
367
389
format: Format :: Context ,
@@ -399,6 +421,7 @@ mod tests {
399
421
params. extend ( [ "foo" , "bar" ] ) ;
400
422
assert_eq ! (
401
423
Ok ( Params {
424
+ executable: os( "diff" ) ,
402
425
from: os( "foo" ) ,
403
426
to: os( "bar" ) ,
404
427
format: Format :: Unified ,
@@ -419,6 +442,7 @@ mod tests {
419
442
params. extend ( [ "foo" , "bar" ] ) ;
420
443
assert_eq ! (
421
444
Ok ( Params {
445
+ executable: os( "diff" ) ,
422
446
from: os( "foo" ) ,
423
447
to: os( "bar" ) ,
424
448
format: Format :: Unified ,
@@ -452,6 +476,7 @@ mod tests {
452
476
fn context_count ( ) {
453
477
assert_eq ! (
454
478
Ok ( Params {
479
+ executable: os( "diff" ) ,
455
480
from: os( "foo" ) ,
456
481
to: os( "bar" ) ,
457
482
format: Format :: Unified ,
@@ -466,6 +491,7 @@ mod tests {
466
491
) ;
467
492
assert_eq ! (
468
493
Ok ( Params {
494
+ executable: os( "diff" ) ,
469
495
from: os( "foo" ) ,
470
496
to: os( "bar" ) ,
471
497
format: Format :: Unified ,
@@ -480,6 +506,7 @@ mod tests {
480
506
) ;
481
507
assert_eq ! (
482
508
Ok ( Params {
509
+ executable: os( "diff" ) ,
483
510
from: os( "foo" ) ,
484
511
to: os( "bar" ) ,
485
512
format: Format :: Unified ,
@@ -494,6 +521,7 @@ mod tests {
494
521
) ;
495
522
assert_eq ! (
496
523
Ok ( Params {
524
+ executable: os( "diff" ) ,
497
525
from: os( "foo" ) ,
498
526
to: os( "bar" ) ,
499
527
format: Format :: Context ,
@@ -511,6 +539,7 @@ mod tests {
511
539
fn report_identical_files ( ) {
512
540
assert_eq ! (
513
541
Ok ( Params {
542
+ executable: os( "diff" ) ,
514
543
from: os( "foo" ) ,
515
544
to: os( "bar" ) ,
516
545
..Default :: default ( )
@@ -519,6 +548,7 @@ mod tests {
519
548
) ;
520
549
assert_eq ! (
521
550
Ok ( Params {
551
+ executable: os( "diff" ) ,
522
552
from: os( "foo" ) ,
523
553
to: os( "bar" ) ,
524
554
report_identical_files: true ,
@@ -528,6 +558,7 @@ mod tests {
528
558
) ;
529
559
assert_eq ! (
530
560
Ok ( Params {
561
+ executable: os( "diff" ) ,
531
562
from: os( "foo" ) ,
532
563
to: os( "bar" ) ,
533
564
report_identical_files: true ,
@@ -549,6 +580,7 @@ mod tests {
549
580
fn brief ( ) {
550
581
assert_eq ! (
551
582
Ok ( Params {
583
+ executable: os( "diff" ) ,
552
584
from: os( "foo" ) ,
553
585
to: os( "bar" ) ,
554
586
..Default :: default ( )
@@ -557,6 +589,7 @@ mod tests {
557
589
) ;
558
590
assert_eq ! (
559
591
Ok ( Params {
592
+ executable: os( "diff" ) ,
560
593
from: os( "foo" ) ,
561
594
to: os( "bar" ) ,
562
595
brief: true ,
@@ -566,6 +599,7 @@ mod tests {
566
599
) ;
567
600
assert_eq ! (
568
601
Ok ( Params {
602
+ executable: os( "diff" ) ,
569
603
from: os( "foo" ) ,
570
604
to: os( "bar" ) ,
571
605
brief: true ,
@@ -582,6 +616,7 @@ mod tests {
582
616
fn expand_tabs ( ) {
583
617
assert_eq ! (
584
618
Ok ( Params {
619
+ executable: os( "diff" ) ,
585
620
from: os( "foo" ) ,
586
621
to: os( "bar" ) ,
587
622
..Default :: default ( )
@@ -591,6 +626,7 @@ mod tests {
591
626
for option in [ "-t" , "--expand-tabs" ] {
592
627
assert_eq ! (
593
628
Ok ( Params {
629
+ executable: os( "diff" ) ,
594
630
from: os( "foo" ) ,
595
631
to: os( "bar" ) ,
596
632
expand_tabs: true ,
@@ -608,6 +644,7 @@ mod tests {
608
644
fn tabsize ( ) {
609
645
assert_eq ! (
610
646
Ok ( Params {
647
+ executable: os( "diff" ) ,
611
648
from: os( "foo" ) ,
612
649
to: os( "bar" ) ,
613
650
..Default :: default ( )
@@ -616,6 +653,7 @@ mod tests {
616
653
) ;
617
654
assert_eq ! (
618
655
Ok ( Params {
656
+ executable: os( "diff" ) ,
619
657
from: os( "foo" ) ,
620
658
to: os( "bar" ) ,
621
659
tabsize: 0 ,
@@ -629,6 +667,7 @@ mod tests {
629
667
) ;
630
668
assert_eq ! (
631
669
Ok ( Params {
670
+ executable: os( "diff" ) ,
632
671
from: os( "foo" ) ,
633
672
to: os( "bar" ) ,
634
673
tabsize: 42 ,
@@ -686,6 +725,7 @@ mod tests {
686
725
fn double_dash ( ) {
687
726
assert_eq ! (
688
727
Ok ( Params {
728
+ executable: os( "diff" ) ,
689
729
from: os( "-g" ) ,
690
730
to: os( "-h" ) ,
691
731
..Default :: default ( )
@@ -697,6 +737,7 @@ mod tests {
697
737
fn default_to_stdin ( ) {
698
738
assert_eq ! (
699
739
Ok ( Params {
740
+ executable: os( "diff" ) ,
700
741
from: os( "foo" ) ,
701
742
to: os( "-" ) ,
702
743
..Default :: default ( )
@@ -705,6 +746,7 @@ mod tests {
705
746
) ;
706
747
assert_eq ! (
707
748
Ok ( Params {
749
+ executable: os( "diff" ) ,
708
750
from: os( "-" ) ,
709
751
to: os( "bar" ) ,
710
752
..Default :: default ( )
@@ -713,6 +755,7 @@ mod tests {
713
755
) ;
714
756
assert_eq ! (
715
757
Ok ( Params {
758
+ executable: os( "diff" ) ,
716
759
from: os( "-" ) ,
717
760
to: os( "-" ) ,
718
761
..Default :: default ( )
0 commit comments