@@ -13,11 +13,11 @@ use self::output::{
1313use anyhow:: { Context , Result } ;
1414use clap:: { ArgMatches , Error , ErrorKind } ;
1515use serde:: Serialize ;
16- use std:: collections:: HashMap ;
1716use std:: fs:: File ;
1817use std:: io:: { Read , Write } ;
1918use std:: ops:: Deref ;
2019use std:: path:: { Path , PathBuf } ;
20+ use std:: { collections:: HashMap , io:: stdin} ;
2121use std:: { env, io:: Cursor } ;
2222use tmc_langs:: { file_util, notification_reporter, CommandError , StyleValidationResult } ;
2323use tmc_langs:: {
@@ -356,7 +356,7 @@ fn run_app(matches: ArgMatches, pretty: bool) -> Result<()> {
356356 } ) ?;
357357
358358 if let Some ( output_path) = output_path {
359- write_result_to_file_as_json ( & exercises, output_path, pretty) ?;
359+ write_result_to_file_as_json ( & exercises, output_path, pretty, None ) ?;
360360 }
361361
362362 let output = Output :: finished_with_data (
@@ -383,7 +383,7 @@ fn run_app(matches: ArgMatches, pretty: bool) -> Result<()> {
383383 } ) ?;
384384
385385 if let Some ( output_path) = output_path {
386- write_result_to_file_as_json ( & config, output_path, pretty) ?;
386+ write_result_to_file_as_json ( & config, output_path, pretty, None ) ?;
387387 }
388388
389389 let output = Output :: finished_with_data (
@@ -568,6 +568,16 @@ fn run_app(matches: ArgMatches, pretty: bool) -> Result<()> {
568568 let output_path = matches. value_of ( "output-path" ) ;
569569 let output_path = output_path. map ( Path :: new) ;
570570
571+ let wait_for_secret = matches. is_present ( "wait-for-secret" ) ;
572+
573+ let secret = if wait_for_secret {
574+ let mut s = String :: new ( ) ;
575+ stdin ( ) . read_line ( & mut s) ?;
576+ Some ( s. trim ( ) . to_string ( ) )
577+ } else {
578+ None
579+ } ;
580+
571581 file_util:: lock!( exercise_path) ;
572582
573583 let test_result = tmc_langs:: run_tests ( exercise_path) . with_context ( || {
@@ -589,7 +599,7 @@ fn run_app(matches: ArgMatches, pretty: bool) -> Result<()> {
589599 } ;
590600
591601 if let Some ( output_path) = output_path {
592- write_result_to_file_as_json ( & test_result, output_path, pretty) ?;
602+ write_result_to_file_as_json ( & test_result, output_path, pretty, secret ) ?;
593603 }
594604
595605 // todo: checkstyle results in stdout?
@@ -635,7 +645,7 @@ fn run_app(matches: ArgMatches, pretty: bool) -> Result<()> {
635645 } ) ?;
636646
637647 if let Some ( output_path) = output_path {
638- write_result_to_file_as_json ( & scan_result, output_path, pretty) ?;
648+ write_result_to_file_as_json ( & scan_result, output_path, pretty, None ) ?;
639649 }
640650
641651 let output = Output :: finished_with_data (
@@ -1266,6 +1276,7 @@ fn write_result_to_file_as_json<T: Serialize>(
12661276 result : & T ,
12671277 output_path : & Path ,
12681278 pretty : bool ,
1279+ secret : Option < String > ,
12691280) -> Result < ( ) > {
12701281 let mut output_file = file_util:: create_file_lock ( output_path) . with_context ( || {
12711282 format ! (
@@ -1275,7 +1286,11 @@ fn write_result_to_file_as_json<T: Serialize>(
12751286 } ) ?;
12761287 let guard = output_file. lock ( ) ?;
12771288
1278- if pretty {
1289+ if let Some ( secret) = secret {
1290+ let token = tmc_langs:: sign_with_jwt ( result, secret. as_bytes ( ) ) ?;
1291+ file_util:: write_to_writer ( token, guard. deref ( ) )
1292+ . with_context ( || format ! ( "Failed to write result to {}" , output_path. display( ) ) ) ?;
1293+ } else if pretty {
12791294 serde_json:: to_writer_pretty ( guard. deref ( ) , result) . with_context ( || {
12801295 format ! (
12811296 "Failed to write result as JSON to {}" ,
0 commit comments