@@ -199,13 +199,21 @@ enum Fail_ {
199
199
/// Convert a `fail_` enum into an error string
200
200
fn fail_str( +f : Fail_ ) -> ~str {
201
201
return match f {
202
- ArgumentMissing ( ref nm) => ~"Argument to option ' " + * nm + ~"' missing. ",
203
- UnrecognizedOption ( ref nm) => ~"Unrecognized option: ' " + * nm + ~"' . ",
204
- OptionMissing ( ref nm) => ~"Required option ' " + * nm + ~"' missing. ",
205
- OptionDuplicated ( ref nm) => ~"Option ' " + * nm + ~"' given more than once. ",
206
- UnexpectedArgument ( ref nm) => {
207
- ~"Option " + *nm + ~" does not take an argument. "
208
- }
202
+ ArgumentMissing ( ref nm) => {
203
+ ~"Argument to option ' " + * nm + ~"' missing. "
204
+ }
205
+ UnrecognizedOption ( ref nm) => {
206
+ ~"Unrecognized option: ' " + * nm + ~"' . "
207
+ }
208
+ OptionMissing ( ref nm) => {
209
+ ~"Required option ' " + * nm + ~"' missing. "
210
+ }
211
+ OptionDuplicated ( ref nm) => {
212
+ ~"Option ' " + * nm + ~"' given more than once. "
213
+ }
214
+ UnexpectedArgument ( ref nm) => {
215
+ ~"Option " + *nm + ~" does not take an argument. "
216
+ }
209
217
} ;
210
218
}
211
219
@@ -476,7 +484,7 @@ mod tests {
476
484
let opts = ~[ reqopt ( ~"test") ] ;
477
485
let rs = getopts ( args, opts) ;
478
486
match rs {
479
- Ok ( m) => {
487
+ Ok ( copy m) => {
480
488
assert ( opt_present ( m, ~"test") ) ;
481
489
assert ( opt_str ( m, ~"test") == ~"20 ") ;
482
490
}
@@ -490,7 +498,7 @@ mod tests {
490
498
let opts = ~[ reqopt ( ~"test") ] ;
491
499
let rs = getopts ( args, opts) ;
492
500
match rs {
493
- Err ( f) => check_fail_type ( f, OptionMissing_ ) ,
501
+ Err ( copy f) => check_fail_type ( f, OptionMissing_ ) ,
494
502
_ => fail
495
503
}
496
504
}
@@ -501,7 +509,7 @@ mod tests {
501
509
let opts = ~[ reqopt ( ~"test") ] ;
502
510
let rs = getopts ( args, opts) ;
503
511
match rs {
504
- Err ( f) => check_fail_type ( f, ArgumentMissing_ ) ,
512
+ Err ( copy f) => check_fail_type ( f, ArgumentMissing_ ) ,
505
513
_ => fail
506
514
}
507
515
}
@@ -512,7 +520,7 @@ mod tests {
512
520
let opts = ~[ reqopt ( ~"test") ] ;
513
521
let rs = getopts ( args, opts) ;
514
522
match rs {
515
- Err ( f) => check_fail_type ( f, OptionDuplicated_ ) ,
523
+ Err ( copy f) => check_fail_type ( f, OptionDuplicated_ ) ,
516
524
_ => fail
517
525
}
518
526
}
@@ -523,7 +531,7 @@ mod tests {
523
531
let opts = ~[ reqopt ( ~"t") ] ;
524
532
let rs = getopts ( args, opts) ;
525
533
match rs {
526
- Ok ( m) => {
534
+ Ok ( copy m) => {
527
535
assert ( opt_present ( m, ~"t") ) ;
528
536
assert ( opt_str ( m, ~"t") == ~"20 ") ;
529
537
}
@@ -537,7 +545,7 @@ mod tests {
537
545
let opts = ~[ reqopt ( ~"t") ] ;
538
546
let rs = getopts ( args, opts) ;
539
547
match rs {
540
- Err ( f) => check_fail_type ( f, OptionMissing_ ) ,
548
+ Err ( copy f) => check_fail_type ( f, OptionMissing_ ) ,
541
549
_ => fail
542
550
}
543
551
}
@@ -548,7 +556,7 @@ mod tests {
548
556
let opts = ~[ reqopt ( ~"t") ] ;
549
557
let rs = getopts ( args, opts) ;
550
558
match rs {
551
- Err ( f) => check_fail_type ( f, ArgumentMissing_ ) ,
559
+ Err ( copy f) => check_fail_type ( f, ArgumentMissing_ ) ,
552
560
_ => fail
553
561
}
554
562
}
@@ -559,7 +567,7 @@ mod tests {
559
567
let opts = ~[ reqopt ( ~"t") ] ;
560
568
let rs = getopts ( args, opts) ;
561
569
match rs {
562
- Err ( f) => check_fail_type ( f, OptionDuplicated_ ) ,
570
+ Err ( copy f) => check_fail_type ( f, OptionDuplicated_ ) ,
563
571
_ => fail
564
572
}
565
573
}
@@ -572,7 +580,7 @@ mod tests {
572
580
let opts = ~[ optopt ( ~"test") ] ;
573
581
let rs = getopts ( args, opts) ;
574
582
match rs {
575
- Ok ( m) => {
583
+ Ok ( copy m) => {
576
584
assert ( opt_present ( m, ~"test") ) ;
577
585
assert ( opt_str ( m, ~"test") == ~"20 ") ;
578
586
}
@@ -586,7 +594,7 @@ mod tests {
586
594
let opts = ~[ optopt ( ~"test") ] ;
587
595
let rs = getopts ( args, opts) ;
588
596
match rs {
589
- Ok ( m) => assert ( !opt_present ( m, ~"test") ) ,
597
+ Ok ( copy m) => assert ( !opt_present ( m, ~"test") ) ,
590
598
_ => fail
591
599
}
592
600
}
@@ -597,7 +605,7 @@ mod tests {
597
605
let opts = ~[ optopt ( ~"test") ] ;
598
606
let rs = getopts ( args, opts) ;
599
607
match rs {
600
- Err ( f) => check_fail_type ( f, ArgumentMissing_ ) ,
608
+ Err ( copy f) => check_fail_type ( f, ArgumentMissing_ ) ,
601
609
_ => fail
602
610
}
603
611
}
@@ -608,7 +616,7 @@ mod tests {
608
616
let opts = ~[ optopt ( ~"test") ] ;
609
617
let rs = getopts ( args, opts) ;
610
618
match rs {
611
- Err ( f) => check_fail_type ( f, OptionDuplicated_ ) ,
619
+ Err ( copy f) => check_fail_type ( f, OptionDuplicated_ ) ,
612
620
_ => fail
613
621
}
614
622
}
@@ -619,7 +627,7 @@ mod tests {
619
627
let opts = ~[ optopt ( ~"t") ] ;
620
628
let rs = getopts ( args, opts) ;
621
629
match rs {
622
- Ok ( m) => {
630
+ Ok ( copy m) => {
623
631
assert ( opt_present ( m, ~"t") ) ;
624
632
assert ( opt_str ( m, ~"t") == ~"20 ") ;
625
633
}
@@ -633,7 +641,7 @@ mod tests {
633
641
let opts = ~[ optopt ( ~"t") ] ;
634
642
let rs = getopts ( args, opts) ;
635
643
match rs {
636
- Ok ( m) => assert ( !opt_present ( m, ~"t") ) ,
644
+ Ok ( copy m) => assert ( !opt_present ( m, ~"t") ) ,
637
645
_ => fail
638
646
}
639
647
}
@@ -644,7 +652,7 @@ mod tests {
644
652
let opts = ~[ optopt ( ~"t") ] ;
645
653
let rs = getopts ( args, opts) ;
646
654
match rs {
647
- Err ( f) => check_fail_type ( f, ArgumentMissing_ ) ,
655
+ Err ( copy f) => check_fail_type ( f, ArgumentMissing_ ) ,
648
656
_ => fail
649
657
}
650
658
}
@@ -655,7 +663,7 @@ mod tests {
655
663
let opts = ~[ optopt ( ~"t") ] ;
656
664
let rs = getopts ( args, opts) ;
657
665
match rs {
658
- Err ( f) => check_fail_type ( f, OptionDuplicated_ ) ,
666
+ Err ( copy f) => check_fail_type ( f, OptionDuplicated_ ) ,
659
667
_ => fail
660
668
}
661
669
}
@@ -668,7 +676,7 @@ mod tests {
668
676
let opts = ~[ optflag ( ~"test") ] ;
669
677
let rs = getopts ( args, opts) ;
670
678
match rs {
671
- Ok ( m) => assert ( opt_present ( m, ~"test") ) ,
679
+ Ok ( copy m) => assert ( opt_present ( m, ~"test") ) ,
672
680
_ => fail
673
681
}
674
682
}
@@ -679,7 +687,7 @@ mod tests {
679
687
let opts = ~[ optflag ( ~"test") ] ;
680
688
let rs = getopts ( args, opts) ;
681
689
match rs {
682
- Ok ( m) => assert ( !opt_present ( m, ~"test") ) ,
690
+ Ok ( copy m) => assert ( !opt_present ( m, ~"test") ) ,
683
691
_ => fail
684
692
}
685
693
}
@@ -690,7 +698,7 @@ mod tests {
690
698
let opts = ~[ optflag ( ~"test") ] ;
691
699
let rs = getopts ( args, opts) ;
692
700
match rs {
693
- Err ( f) => {
701
+ Err ( copy f) => {
694
702
log ( error, fail_str ( f) ) ;
695
703
check_fail_type ( f, UnexpectedArgument_ ) ;
696
704
}
@@ -704,7 +712,7 @@ mod tests {
704
712
let opts = ~[ optflag ( ~"test") ] ;
705
713
let rs = getopts ( args, opts) ;
706
714
match rs {
707
- Err ( f) => check_fail_type ( f, OptionDuplicated_ ) ,
715
+ Err ( copy f) => check_fail_type ( f, OptionDuplicated_ ) ,
708
716
_ => fail
709
717
}
710
718
}
@@ -715,7 +723,7 @@ mod tests {
715
723
let opts = ~[ optflag ( ~"t") ] ;
716
724
let rs = getopts ( args, opts) ;
717
725
match rs {
718
- Ok ( m) => assert ( opt_present ( m, ~"t") ) ,
726
+ Ok ( copy m) => assert ( opt_present ( m, ~"t") ) ,
719
727
_ => fail
720
728
}
721
729
}
@@ -726,7 +734,7 @@ mod tests {
726
734
let opts = ~[ optflag ( ~"t") ] ;
727
735
let rs = getopts ( args, opts) ;
728
736
match rs {
729
- Ok ( m) => assert ( !opt_present ( m, ~"t") ) ,
737
+ Ok ( copy m) => assert ( !opt_present ( m, ~"t") ) ,
730
738
_ => fail
731
739
}
732
740
}
@@ -737,7 +745,7 @@ mod tests {
737
745
let opts = ~[ optflag ( ~"t") ] ;
738
746
let rs = getopts ( args, opts) ;
739
747
match rs {
740
- Ok ( m) => {
748
+ Ok ( ref m) => {
741
749
// The next variable after the flag is just a free argument
742
750
743
751
assert ( m. free [ 0 ] == ~"20 ") ;
@@ -752,7 +760,7 @@ mod tests {
752
760
let opts = ~[ optflag ( ~"t") ] ;
753
761
let rs = getopts ( args, opts) ;
754
762
match rs {
755
- Err ( f) => check_fail_type ( f, OptionDuplicated_ ) ,
763
+ Err ( copy f) => check_fail_type ( f, OptionDuplicated_ ) ,
756
764
_ => fail
757
765
}
758
766
}
@@ -765,7 +773,7 @@ mod tests {
765
773
let opts = ~[ optmulti ( ~"test") ] ;
766
774
let rs = getopts ( args, opts) ;
767
775
match rs {
768
- Ok ( m) => {
776
+ Ok ( copy m) => {
769
777
assert ( opt_present ( m, ~"test") ) ;
770
778
assert ( opt_str ( m, ~"test") == ~"20 ") ;
771
779
}
@@ -779,7 +787,7 @@ mod tests {
779
787
let opts = ~[ optmulti ( ~"test") ] ;
780
788
let rs = getopts ( args, opts) ;
781
789
match rs {
782
- Ok ( m) => assert ( !opt_present ( m, ~"test") ) ,
790
+ Ok ( copy m) => assert ( !opt_present ( m, ~"test") ) ,
783
791
_ => fail
784
792
}
785
793
}
@@ -790,7 +798,7 @@ mod tests {
790
798
let opts = ~[ optmulti ( ~"test") ] ;
791
799
let rs = getopts ( args, opts) ;
792
800
match rs {
793
- Err ( f) => check_fail_type ( f, ArgumentMissing_ ) ,
801
+ Err ( copy f) => check_fail_type ( f, ArgumentMissing_ ) ,
794
802
_ => fail
795
803
}
796
804
}
@@ -801,7 +809,7 @@ mod tests {
801
809
let opts = ~[ optmulti ( ~"test") ] ;
802
810
let rs = getopts ( args, opts) ;
803
811
match rs {
804
- Ok ( m) => {
812
+ Ok ( copy m) => {
805
813
assert ( opt_present ( m, ~"test") ) ;
806
814
assert ( opt_str ( m, ~"test") == ~"20 ") ;
807
815
let pair = opt_strs ( m, ~"test") ;
@@ -818,7 +826,7 @@ mod tests {
818
826
let opts = ~[ optmulti ( ~"t") ] ;
819
827
let rs = getopts ( args, opts) ;
820
828
match rs {
821
- Ok ( m) => {
829
+ Ok ( copy m) => {
822
830
assert ( opt_present ( m, ~"t") ) ;
823
831
assert ( opt_str ( m, ~"t") == ~"20 ") ;
824
832
}
@@ -832,7 +840,7 @@ mod tests {
832
840
let opts = ~[ optmulti ( ~"t") ] ;
833
841
let rs = getopts ( args, opts) ;
834
842
match rs {
835
- Ok ( m) => assert ( !opt_present ( m, ~"t") ) ,
843
+ Ok ( copy m) => assert ( !opt_present ( m, ~"t") ) ,
836
844
_ => fail
837
845
}
838
846
}
@@ -843,7 +851,7 @@ mod tests {
843
851
let opts = ~[ optmulti ( ~"t") ] ;
844
852
let rs = getopts ( args, opts) ;
845
853
match rs {
846
- Err ( f) => check_fail_type ( f, ArgumentMissing_ ) ,
854
+ Err ( copy f) => check_fail_type ( f, ArgumentMissing_ ) ,
847
855
_ => fail
848
856
}
849
857
}
@@ -854,7 +862,7 @@ mod tests {
854
862
let opts = ~[ optmulti ( ~"t") ] ;
855
863
let rs = getopts ( args, opts) ;
856
864
match rs {
857
- Ok ( m) => {
865
+ Ok ( copy m) => {
858
866
assert ( opt_present ( m, ~"t") ) ;
859
867
assert ( opt_str ( m, ~"t") == ~"20 ") ;
860
868
let pair = opt_strs ( m, ~"t") ;
@@ -871,7 +879,7 @@ mod tests {
871
879
let opts = ~[ optmulti ( ~"t") ] ;
872
880
let rs = getopts ( args, opts) ;
873
881
match rs {
874
- Err ( f) => check_fail_type ( f, UnrecognizedOption_ ) ,
882
+ Err ( copy f) => check_fail_type ( f, UnrecognizedOption_ ) ,
875
883
_ => fail
876
884
}
877
885
}
@@ -882,7 +890,7 @@ mod tests {
882
890
let opts = ~[ optmulti ( ~"test") ] ;
883
891
let rs = getopts ( args, opts) ;
884
892
match rs {
885
- Err ( f) => check_fail_type ( f, UnrecognizedOption_ ) ,
893
+ Err ( copy f) => check_fail_type ( f, UnrecognizedOption_ ) ,
886
894
_ => fail
887
895
}
888
896
}
@@ -899,7 +907,7 @@ mod tests {
899
907
optopt ( ~"notpresent") ] ;
900
908
let rs = getopts ( args, opts) ;
901
909
match rs {
902
- Ok ( m) => {
910
+ Ok ( copy m) => {
903
911
assert ( m. free [ 0 ] == ~"prog") ;
904
912
assert ( m. free [ 1 ] == ~"free1") ;
905
913
assert ( opt_str ( m, ~"s") == ~"20 ") ;
@@ -924,8 +932,8 @@ mod tests {
924
932
let args = ~[ ~"-e", ~"foo", ~"--encrypt", ~"foo"] ;
925
933
let opts = ~[ optopt ( ~"e") , optopt ( ~"encrypt") ] ;
926
934
let matches = match getopts ( args, opts) {
927
- result:: Ok ( m) => m,
928
- result:: Err ( _f ) => fail
935
+ result:: Ok ( move m) => m,
936
+ result:: Err ( _ ) => fail
929
937
} ;
930
938
assert opts_present ( matches, ~[ ~"e"] ) ;
931
939
assert opts_present ( matches, ~[ ~"encrypt"] ) ;
@@ -945,8 +953,8 @@ mod tests {
945
953
let args = ~[~" -Lfoo "];
946
954
let opts = ~[optmulti(~" L ")];
947
955
let matches = match getopts(args, opts) {
948
- result::Ok(m) => m,
949
- result::Err(_f ) => fail
956
+ result::Ok(move m) => m,
957
+ result::Err(_ ) => fail
950
958
};
951
959
assert opts_present(matches, ~[~" L "]);
952
960
assert opts_str(matches, ~[~" L "]) == ~" foo";
0 commit comments