@@ -19,7 +19,7 @@ use tmc_langs_core::oauth2::{
1919 basic:: BasicTokenType , AccessToken , EmptyExtraTokenFields , Scope , StandardTokenResponse ,
2020} ;
2121use tmc_langs_core:: { FeedbackAnswer , TmcCore , Token } ;
22- use tmc_langs_framework:: io:: submission_processing;
22+ use tmc_langs_framework:: { domain :: ValidationResult , io:: submission_processing} ;
2323use tmc_langs_util:: {
2424 task_executor:: { self , TmcParams } ,
2525 Language ,
@@ -70,20 +70,20 @@ fn run() -> Result<()> {
7070 let exercise_path = matches. value_of ( "exercise-path" ) . unwrap ( ) ;
7171 let exercise_path = Path :: new ( exercise_path) ;
7272
73- let output_path = matches. value_of ( "output-path" ) . unwrap ( ) ;
74- let output_path = Path :: new ( output_path ) ;
73+ let output_path = matches. value_of ( "output-path" ) ;
74+ let output_path = output_path . map ( Path :: new) ;
7575
7676 let locale = matches. value_of ( "locale" ) . unwrap ( ) ;
7777 let locale = into_locale ( locale) ?;
7878
79- run_checkstyle ( exercise_path, output_path, locale) ?;
79+ let check_result = run_checkstyle_write_results ( exercise_path, output_path, locale) ?;
8080
81- let output = Output :: < ( ) > {
81+ let output = Output {
8282 status : Status :: Successful ,
8383 message : Some ( "ran checkstyle" . to_string ( ) ) ,
8484 result : OutputResult :: ExecutedCommand ,
8585 percent_done : 1.0 ,
86- data : None ,
86+ data : check_result ,
8787 } ;
8888 print_output ( & output) ?
8989 } else if let Some ( matches) = matches. subcommand_matches ( "compress-project" ) {
@@ -269,9 +269,10 @@ fn run() -> Result<()> {
269269 let exercise_path = matches. value_of ( "exercise-path" ) . unwrap ( ) ;
270270 let exercise_path = Path :: new ( exercise_path) ;
271271
272- let output_path = matches. value_of ( "output-path" ) . unwrap ( ) ;
273- let output_path = Path :: new ( output_path ) ;
272+ let output_path = matches. value_of ( "output-path" ) ;
273+ let output_path = output_path . map ( Path :: new) ;
274274
275+ // todo: checkstyle results in stdout?
275276 let checkstyle_output_path = matches. value_of ( "checkstyle-output-path" ) ;
276277 let checkstyle_output_path: Option < & Path > = checkstyle_output_path. map ( Path :: new) ;
277278
@@ -282,13 +283,15 @@ fn run() -> Result<()> {
282283 )
283284 } ) ?;
284285
285- write_result_to_file_as_json ( & test_result, output_path) ?;
286+ if let Some ( output_path) = output_path {
287+ write_result_to_file_as_json ( & test_result, output_path) ?;
288+ }
286289
287290 if let Some ( checkstyle_output_path) = checkstyle_output_path {
288291 let locale = matches. value_of ( "locale" ) . unwrap ( ) ;
289292 let locale = into_locale ( locale) ?;
290293
291- run_checkstyle ( exercise_path, checkstyle_output_path, locale) ?;
294+ run_checkstyle_write_results ( exercise_path, Some ( checkstyle_output_path) , locale) ?;
292295 }
293296
294297 let output = Output {
@@ -303,8 +306,8 @@ fn run() -> Result<()> {
303306 let exercise_path = matches. value_of ( "exercise-path" ) . unwrap ( ) ;
304307 let exercise_path = Path :: new ( exercise_path) ;
305308
306- let output_path = matches. value_of ( "output-path" ) . unwrap ( ) ;
307- let output_path = Path :: new ( output_path ) ;
309+ let output_path = matches. value_of ( "output-path" ) ;
310+ let output_path = output_path . map ( Path :: new) ;
308311
309312 let exercise_name = exercise_path. file_name ( ) . with_context ( || {
310313 format ! (
@@ -323,7 +326,9 @@ fn run() -> Result<()> {
323326 let scan_result = task_executor:: scan_exercise ( exercise_path, exercise_name. to_string ( ) )
324327 . with_context ( || format ! ( "Failed to scan exercise at {}" , exercise_path. display( ) ) ) ?;
325328
326- write_result_to_file_as_json ( & scan_result, output_path) ?;
329+ if let Some ( output_path) = output_path {
330+ write_result_to_file_as_json ( & scan_result, output_path) ?;
331+ }
327332
328333 let output = Output {
329334 status : Status :: Successful ,
@@ -337,8 +342,8 @@ fn run() -> Result<()> {
337342 let exercise_path = matches. value_of ( "exercise-path" ) . unwrap ( ) ;
338343 let exercise_path = Path :: new ( exercise_path) ;
339344
340- let output_path = matches. value_of ( "output-path" ) . unwrap ( ) ;
341- let output_path = Path :: new ( output_path ) ;
345+ let output_path = matches. value_of ( "output-path" ) ;
346+ let output_path = output_path . map ( Path :: new) ;
342347
343348 let mut exercises = vec ! [ ] ;
344349 // silently skips errors
@@ -356,7 +361,9 @@ fn run() -> Result<()> {
356361 }
357362 }
358363
359- write_result_to_file_as_json ( & exercises, output_path) ?;
364+ if let Some ( output_path) = output_path {
365+ write_result_to_file_as_json ( & exercises, output_path) ?;
366+ }
360367
361368 let output = Output {
362369 status : Status :: Successful ,
@@ -371,8 +378,8 @@ fn run() -> Result<()> {
371378 let exercise_path = matches. value_of ( "exercise-path" ) . unwrap ( ) ;
372379 let exercise_path = Path :: new ( exercise_path) ;
373380
374- let output_path = matches. value_of ( "output-path" ) . unwrap ( ) ;
375- let output_path = Path :: new ( output_path ) ;
381+ let output_path = matches. value_of ( "output-path" ) ;
382+ let output_path = output_path . map ( Path :: new) ;
376383
377384 let config = task_executor:: get_exercise_packaging_configuration ( exercise_path)
378385 . with_context ( || {
@@ -382,7 +389,9 @@ fn run() -> Result<()> {
382389 )
383390 } ) ?;
384391
385- write_result_to_file_as_json ( & config, output_path) ?;
392+ if let Some ( output_path) = output_path {
393+ write_result_to_file_as_json ( & config, output_path) ?;
394+ }
386395
387396 let output = Output {
388397 status : Status :: Successful ,
@@ -1067,15 +1076,20 @@ fn find_exercise_directories(exercise_path: &Path) -> Vec<PathBuf> {
10671076 paths
10681077}
10691078
1070- fn run_checkstyle ( exercise_path : & Path , output_path : & Path , locale : Language ) -> Result < ( ) > {
1079+ // if output_path is Some, the checkstyle results are written to that path
1080+ fn run_checkstyle_write_results (
1081+ exercise_path : & Path ,
1082+ output_path : Option < & Path > ,
1083+ locale : Language ,
1084+ ) -> Result < Option < ValidationResult > > {
10711085 let check_result =
10721086 task_executor:: run_check_code_style ( exercise_path, locale) . with_context ( || {
10731087 format ! (
10741088 "Failed to check code style for project at {}" ,
10751089 exercise_path. display( )
10761090 )
10771091 } ) ?;
1078- if let Some ( check_result ) = check_result {
1092+ if let Some ( output_path ) = output_path {
10791093 let output_file = File :: create ( output_path) . with_context ( || {
10801094 format ! (
10811095 "Failed to create code style check results file at {}" ,
@@ -1089,5 +1103,5 @@ fn run_checkstyle(exercise_path: &Path, output_path: &Path, locale: Language) ->
10891103 )
10901104 } ) ?;
10911105 }
1092- Ok ( ( ) )
1106+ Ok ( check_result )
10931107}
0 commit comments