@@ -301,8 +301,16 @@ impl App {
301301 file. read_to_string ( & mut file_content) ?;
302302
303303 self . submission_task = Some ( tokio:: spawn ( async move {
304- service:: submit_solution ( & client, & filepath, & file_content, & leaderboard, & gpu, & mode)
305- . await
304+ service:: submit_solution (
305+ & client,
306+ & filepath,
307+ & file_content,
308+ & leaderboard,
309+ & gpu,
310+ & mode,
311+ None ,
312+ )
313+ . await
306314 } ) ) ;
307315 Ok ( ( ) )
308316 }
@@ -672,3 +680,110 @@ pub async fn run_submit_tui(
672680
673681 Ok ( ( ) )
674682}
683+
684+ pub async fn run_submit_plain (
685+ filepath : Option < String > ,
686+ gpu : Option < String > ,
687+ leaderboard : Option < String > ,
688+ mode : Option < String > ,
689+ cli_id : String ,
690+ output : Option < String > ,
691+ ) -> Result < ( ) > {
692+ let file_to_submit = match filepath {
693+ Some ( fp) => fp,
694+ None => {
695+ return Err ( anyhow ! ( "File path is required when using --no-tui" ) ) ;
696+ }
697+ } ;
698+
699+ if !Path :: new ( & file_to_submit) . exists ( ) {
700+ return Err ( anyhow ! ( "File not found: {}" , file_to_submit) ) ;
701+ }
702+
703+ let ( directives, has_multiple_gpus) = utils:: get_popcorn_directives ( & file_to_submit) ?;
704+
705+ if has_multiple_gpus {
706+ return Err ( anyhow ! (
707+ "Multiple GPUs are not supported yet. Please specify only one GPU."
708+ ) ) ;
709+ }
710+
711+ // Determine final values
712+ let final_gpu = gpu
713+ . or_else ( || {
714+ if !directives. gpus . is_empty ( ) {
715+ Some ( directives. gpus [ 0 ] . clone ( ) )
716+ } else {
717+ None
718+ }
719+ } )
720+ . ok_or_else ( || anyhow ! ( "GPU not specified. Use --gpu flag or add GPU directive to file" ) ) ?;
721+
722+ let final_leaderboard = leaderboard
723+ . or_else ( || {
724+ if !directives. leaderboard_name . is_empty ( ) {
725+ Some ( directives. leaderboard_name . clone ( ) )
726+ } else {
727+ None
728+ }
729+ } )
730+ . ok_or_else ( || {
731+ anyhow ! ( "Leaderboard not specified. Use --leaderboard flag or add leaderboard directive to file" )
732+ } ) ?;
733+
734+ let final_mode = mode. ok_or_else ( || {
735+ anyhow ! ( "Submission mode not specified. Use --mode flag (test, benchmark, leaderboard, profile)" )
736+ } ) ?;
737+
738+ // Read file content
739+ let mut file = File :: open ( & file_to_submit) ?;
740+ let mut file_content = String :: new ( ) ;
741+ file. read_to_string ( & mut file_content) ?;
742+
743+ eprintln ! ( "Submitting to leaderboard: {}" , final_leaderboard) ;
744+ eprintln ! ( "GPU: {}" , final_gpu) ;
745+ eprintln ! ( "Mode: {}" , final_mode) ;
746+ eprintln ! ( "File: {}" , file_to_submit) ;
747+ eprintln ! ( "\n Waiting for results..." ) ;
748+
749+ // Create client and submit
750+ let client = service:: create_client ( Some ( cli_id) ) ?;
751+ let result = service:: submit_solution (
752+ & client,
753+ & file_to_submit,
754+ & file_content,
755+ & final_leaderboard,
756+ & final_gpu,
757+ & final_mode,
758+ Some ( Box :: new ( |msg| {
759+ eprintln ! ( "{}" , msg) ;
760+ } ) ) ,
761+ )
762+ . await ?;
763+
764+ // Clean up the result text
765+ let trimmed = result. trim ( ) ;
766+ let content = if trimmed. starts_with ( '[' ) && trimmed. ends_with ( ']' ) && trimmed. len ( ) >= 2 {
767+ & trimmed[ 1 ..trimmed. len ( ) - 1 ]
768+ } else {
769+ trimmed
770+ } ;
771+
772+ let content = content. replace ( "\\ n" , "\n " ) ;
773+
774+ // Write to file if output is specified
775+ if let Some ( output_path) = output {
776+ if let Some ( parent) = Path :: new ( & output_path) . parent ( ) {
777+ std:: fs:: create_dir_all ( parent)
778+ . map_err ( |e| anyhow ! ( "Failed to create directories for {}: {}" , output_path, e) ) ?;
779+ }
780+ std:: fs:: write ( & output_path, & content)
781+ . map_err ( |e| anyhow ! ( "Failed to write result to file {}: {}" , output_path, e) ) ?;
782+ eprintln ! ( "\n Results written to: {}" , output_path) ;
783+ }
784+
785+ // Print to stdout
786+ println ! ( "\n {}" , content) ;
787+
788+ Ok ( ( ) )
789+ }
0 commit comments