@@ -64,7 +64,8 @@ fn main() {
64
64
fn run ( ) -> Result < ( ) > {
65
65
let matches = app:: create_app ( ) . get_matches ( ) ;
66
66
67
- match matches. subcommand ( ) {
67
+ // enforces that each branch must return a PrintToken as proof of having printed the output
68
+ let _printed: PrintToken = match matches. subcommand ( ) {
68
69
( "checkstyle" , Some ( matches) ) => {
69
70
let exercise_path = matches. value_of ( "exercise-path" ) . unwrap ( ) ;
70
71
let exercise_path = Path :: new ( exercise_path) ;
@@ -437,11 +438,11 @@ fn run() -> Result<()> {
437
438
}
438
439
( "core" , Some ( matches) ) => run_core ( matches) ?,
439
440
_ => unreachable ! ( ) ,
440
- }
441
+ } ;
441
442
Ok ( ( ) )
442
443
}
443
444
444
- fn run_core ( matches : & ArgMatches ) -> Result < ( ) > {
445
+ fn run_core ( matches : & ArgMatches ) -> Result < PrintToken > {
445
446
let root_url =
446
447
env:: var ( "TMC_LANGS_ROOT_URL" ) . unwrap_or_else ( |_| "https://tmc.mooc.fi" . to_string ( ) ) ;
447
448
let client_name = matches. value_of ( "client-name" ) . unwrap ( ) ;
@@ -462,7 +463,8 @@ fn run_core(matches: &ArgMatches) -> Result<()> {
462
463
percent_done : update. percent_done ,
463
464
data : None ,
464
465
} ;
465
- print_output ( & output) . map_err ( |e| e. into ( ) )
466
+ print_output ( & output) ?;
467
+ Ok ( ( ) )
466
468
} ) ;
467
469
468
470
// set token if a credentials.json is found for the client name
@@ -491,7 +493,7 @@ fn run_core(matches: &ArgMatches) -> Result<()> {
491
493
}
492
494
} ;
493
495
494
- match matches. subcommand ( ) {
496
+ let printed : PrintToken = match matches. subcommand ( ) {
495
497
( "login" , Some ( matches) ) => {
496
498
let email = matches. value_of ( "email" ) ;
497
499
let set_access_token = matches. value_of ( "set-access-token" ) ;
@@ -555,7 +557,7 @@ fn run_core(matches: &ArgMatches) -> Result<()> {
555
557
percent_done : 1.0 ,
556
558
data : None ,
557
559
} ;
558
- print_output ( & output) ?;
560
+ print_output ( & output) ?
559
561
}
560
562
( "logout" , Some ( _matches) ) => {
561
563
if credentials_path. exists ( ) {
@@ -574,7 +576,7 @@ fn run_core(matches: &ArgMatches) -> Result<()> {
574
576
percent_done : 1.0 ,
575
577
data : None ,
576
578
} ;
577
- print_output ( & output) ?;
579
+ print_output ( & output) ?
578
580
}
579
581
( "logged-in" , Some ( _matches) ) => {
580
582
if credentials_path. exists ( ) {
@@ -597,7 +599,7 @@ fn run_core(matches: &ArgMatches) -> Result<()> {
597
599
percent_done : 1.0 ,
598
600
data : Some ( token) ,
599
601
} ;
600
- print_output ( & output) ?;
602
+ print_output ( & output) ?
601
603
} else {
602
604
let output = Output :: < ( ) > {
603
605
status : Status :: Successful ,
@@ -606,7 +608,7 @@ fn run_core(matches: &ArgMatches) -> Result<()> {
606
608
percent_done : 1.0 ,
607
609
data : None ,
608
610
} ;
609
- print_output ( & output) ?;
611
+ print_output ( & output) ?
610
612
}
611
613
}
612
614
( "get-organizations" , Some ( _matches) ) => {
@@ -621,7 +623,7 @@ fn run_core(matches: &ArgMatches) -> Result<()> {
621
623
percent_done : 1.0 ,
622
624
data : Some ( orgs) ,
623
625
} ;
624
- print_output ( & output) ?;
626
+ print_output ( & output) ?
625
627
}
626
628
( "get-organization" , Some ( matches) ) => {
627
629
let organization_slug = matches. value_of ( "organization" ) . unwrap ( ) ;
@@ -636,7 +638,7 @@ fn run_core(matches: &ArgMatches) -> Result<()> {
636
638
percent_done : 1.0 ,
637
639
data : Some ( org) ,
638
640
} ;
639
- print_output ( & output) ?;
641
+ print_output ( & output) ?
640
642
}
641
643
( "download-or-update-exercises" , Some ( matches) ) => {
642
644
let mut exercise_args = matches. values_of ( "exercise" ) . unwrap ( ) ;
@@ -658,7 +660,7 @@ fn run_core(matches: &ArgMatches) -> Result<()> {
658
660
percent_done : 1.0 ,
659
661
data : None ,
660
662
} ;
661
- print_output ( & output) ?;
663
+ print_output ( & output) ?
662
664
}
663
665
( "get-course-details" , Some ( matches) ) => {
664
666
let course_id = matches. value_of ( "course-id" ) . unwrap ( ) ;
@@ -675,7 +677,7 @@ fn run_core(matches: &ArgMatches) -> Result<()> {
675
677
percent_done : 1.0 ,
676
678
data : Some ( course_details) ,
677
679
} ;
678
- print_output ( & output) ?;
680
+ print_output ( & output) ?
679
681
}
680
682
( "get-courses" , Some ( matches) ) => {
681
683
let organization_slug = matches. value_of ( "organization" ) . unwrap ( ) ;
@@ -690,7 +692,7 @@ fn run_core(matches: &ArgMatches) -> Result<()> {
690
692
percent_done : 1.0 ,
691
693
data : Some ( courses) ,
692
694
} ;
693
- print_output ( & output) ?;
695
+ print_output ( & output) ?
694
696
}
695
697
( "get-course-settings" , Some ( matches) ) => {
696
698
let course_id = matches. value_of ( "course-id" ) . unwrap ( ) ;
@@ -704,7 +706,7 @@ fn run_core(matches: &ArgMatches) -> Result<()> {
704
706
percent_done : 1.0 ,
705
707
data : Some ( course) ,
706
708
} ;
707
- print_output ( & output) ?;
709
+ print_output ( & output) ?
708
710
}
709
711
( "get-course-exercises" , Some ( matches) ) => {
710
712
let course_id = matches. value_of ( "course-id" ) . unwrap ( ) ;
@@ -720,7 +722,7 @@ fn run_core(matches: &ArgMatches) -> Result<()> {
720
722
percent_done : 1.0 ,
721
723
data : Some ( course) ,
722
724
} ;
723
- print_output ( & output) ?;
725
+ print_output ( & output) ?
724
726
}
725
727
( "get-exercise-details" , Some ( matches) ) => {
726
728
let exercise_id = matches. value_of ( "exercise-id" ) . unwrap ( ) ;
@@ -736,7 +738,7 @@ fn run_core(matches: &ArgMatches) -> Result<()> {
736
738
percent_done : 1.0 ,
737
739
data : Some ( course) ,
738
740
} ;
739
- print_output ( & output) ?;
741
+ print_output ( & output) ?
740
742
}
741
743
( "paste" , Some ( matches) ) => {
742
744
let submission_url = matches. value_of ( "submission-url" ) . unwrap ( ) ;
@@ -769,7 +771,7 @@ fn run_core(matches: &ArgMatches) -> Result<()> {
769
771
percent_done : 1.0 ,
770
772
data : Some ( new_submission) ,
771
773
} ;
772
- print_output ( & output) ?;
774
+ print_output ( & output) ?
773
775
}
774
776
( "run-checkstyle" , Some ( matches) ) => {
775
777
let exercise_path = matches. value_of ( "exercise-path" ) . unwrap ( ) ;
@@ -788,7 +790,7 @@ fn run_core(matches: &ArgMatches) -> Result<()> {
788
790
percent_done : 1.0 ,
789
791
data : Some ( validation_result) ,
790
792
} ;
791
- print_output ( & output) ?;
793
+ print_output ( & output) ?
792
794
}
793
795
( "run-tests" , Some ( matches) ) => {
794
796
let exercise_path = matches. value_of ( "exercise-path" ) . unwrap ( ) ;
@@ -805,7 +807,7 @@ fn run_core(matches: &ArgMatches) -> Result<()> {
805
807
percent_done : 1.0 ,
806
808
data : Some ( run_result) ,
807
809
} ;
808
- print_output ( & output) ?;
810
+ print_output ( & output) ?
809
811
}
810
812
( "send-feedback" , Some ( matches) ) => {
811
813
let feedback_url = matches. value_of ( "feedback-url" ) . unwrap ( ) ;
@@ -833,7 +835,7 @@ fn run_core(matches: &ArgMatches) -> Result<()> {
833
835
percent_done : 1.0 ,
834
836
data : Some ( response) ,
835
837
} ;
836
- print_output ( & output) ?;
838
+ print_output ( & output) ?
837
839
}
838
840
( "submit" , Some ( matches) ) => {
839
841
let submission_url = matches. value_of ( "submission-url" ) . unwrap ( ) ;
@@ -864,7 +866,7 @@ fn run_core(matches: &ArgMatches) -> Result<()> {
864
866
data : Some ( new_submission) ,
865
867
} ;
866
868
867
- print_output ( & output) ?;
869
+ print_output ( & output) ?
868
870
} else {
869
871
// same as wait-for-submission
870
872
let submission_url = new_submission. submission_url ;
@@ -881,7 +883,7 @@ fn run_core(matches: &ArgMatches) -> Result<()> {
881
883
percent_done : 1.0 ,
882
884
data : Some ( submission_finished) ,
883
885
} ;
884
- print_output ( & output) ?;
886
+ print_output ( & output) ?
885
887
}
886
888
}
887
889
( "get-exercise-submissions" , Some ( matches) ) => {
@@ -898,7 +900,7 @@ fn run_core(matches: &ArgMatches) -> Result<()> {
898
900
percent_done : 1.0 ,
899
901
data : Some ( submissions) ,
900
902
} ;
901
- print_output ( & output) ?;
903
+ print_output ( & output) ?
902
904
}
903
905
( "wait-for-submission" , Some ( matches) ) => {
904
906
let submission_url = matches. value_of ( "submission-url" ) . unwrap ( ) ;
@@ -915,7 +917,7 @@ fn run_core(matches: &ArgMatches) -> Result<()> {
915
917
percent_done : 1.0 ,
916
918
data : Some ( submission_finished) ,
917
919
} ;
918
- print_output ( & output) ?;
920
+ print_output ( & output) ?
919
921
}
920
922
( "get-exercise-updates" , Some ( matches) ) => {
921
923
let course_id = matches. value_of ( "course-id" ) . unwrap ( ) ;
@@ -940,7 +942,7 @@ fn run_core(matches: &ArgMatches) -> Result<()> {
940
942
percent_done : 1.0 ,
941
943
data : Some ( update_result) ,
942
944
} ;
943
- print_output ( & output) ?;
945
+ print_output ( & output) ?
944
946
}
945
947
( "mark-review-as-read" , Some ( matches) ) => {
946
948
let review_update_url = matches. value_of ( "review-update-url" ) . unwrap ( ) ;
@@ -954,7 +956,7 @@ fn run_core(matches: &ArgMatches) -> Result<()> {
954
956
percent_done : 1.0 ,
955
957
data : None ,
956
958
} ;
957
- print_output ( & output) ?;
959
+ print_output ( & output) ?
958
960
}
959
961
( "get-unread-reviews" , Some ( matches) ) => {
960
962
let reviews_url = matches. value_of ( "reviews-url" ) . unwrap ( ) ;
@@ -971,7 +973,7 @@ fn run_core(matches: &ArgMatches) -> Result<()> {
971
973
percent_done : 1.0 ,
972
974
data : Some ( reviews) ,
973
975
} ;
974
- print_output ( & output) ?;
976
+ print_output ( & output) ?
975
977
}
976
978
( "request-code-review" , Some ( matches) ) => {
977
979
let submission_url = matches. value_of ( "submission-url" ) . unwrap ( ) ;
@@ -1005,7 +1007,7 @@ fn run_core(matches: &ArgMatches) -> Result<()> {
1005
1007
percent_done : 1.0 ,
1006
1008
data : Some ( new_submission) ,
1007
1009
} ;
1008
- print_output ( & output) ?;
1010
+ print_output ( & output) ?
1009
1011
}
1010
1012
( "download-model-solution" , Some ( matches) ) => {
1011
1013
let solution_download_url = matches. value_of ( "solution-download-url" ) . unwrap ( ) ;
@@ -1024,7 +1026,7 @@ fn run_core(matches: &ArgMatches) -> Result<()> {
1024
1026
percent_done : 1.0 ,
1025
1027
data : None ,
1026
1028
} ;
1027
- print_output ( & output) ?;
1029
+ print_output ( & output) ?
1028
1030
}
1029
1031
( "reset-exercise" , Some ( matches) ) => {
1030
1032
let exercise_path = matches. value_of ( "exercise-path" ) . unwrap ( ) ;
@@ -1049,7 +1051,7 @@ fn run_core(matches: &ArgMatches) -> Result<()> {
1049
1051
percent_done : 1.0 ,
1050
1052
data : None ,
1051
1053
} ;
1052
- print_output ( & output) ?;
1054
+ print_output ( & output) ?
1053
1055
}
1054
1056
( "download-old-submission" , Some ( matches) ) => {
1055
1057
let exercise_id = matches. value_of ( "exercise-id" ) . unwrap ( ) ;
@@ -1081,19 +1083,19 @@ fn run_core(matches: &ArgMatches) -> Result<()> {
1081
1083
percent_done : 1.0 ,
1082
1084
data : None ,
1083
1085
} ;
1084
- print_output ( & output) ?;
1086
+ print_output ( & output) ?
1085
1087
}
1086
1088
_ => unreachable ! ( ) ,
1087
- }
1089
+ } ;
1088
1090
1089
- Ok ( ( ) )
1091
+ Ok ( printed )
1090
1092
}
1091
1093
1092
- fn print_output < T : Serialize + Debug > ( output : & Output < T > ) -> Result < ( ) > {
1094
+ fn print_output < T : Serialize + Debug > ( output : & Output < T > ) -> Result < PrintToken > {
1093
1095
let result = serde_json:: to_string ( & output)
1094
1096
. with_context ( || format ! ( "Failed to convert {:?} to JSON" , output) ) ?;
1095
1097
println ! ( "{}" , result) ;
1096
- Ok ( ( ) )
1098
+ Ok ( PrintToken )
1097
1099
}
1098
1100
1099
1101
fn write_result_to_file_as_json < T : Serialize > ( result : & T , output_path : & Path ) -> Result < ( ) > {
@@ -1186,3 +1188,5 @@ fn run_checkstyle_write_results(
1186
1188
}
1187
1189
Ok ( check_result)
1188
1190
}
1191
+
1192
+ struct PrintToken ;
0 commit comments