@@ -596,7 +596,13 @@ fn centered_rect(percent_x: u16, percent_y: u16, r: Rect) -> Rect {
596596 . split ( popup_layout[ 1 ] ) [ 1 ]
597597}
598598
599- pub async fn run_submit_tui ( filepath : Option < String > , cli_id : String ) -> Result < ( ) > {
599+ pub async fn run_submit_tui (
600+ filepath : Option < String > ,
601+ gpu : Option < String > ,
602+ leaderboard : Option < String > ,
603+ mode : Option < String > ,
604+ cli_id : String ,
605+ ) -> Result < ( ) > {
600606 let file_to_submit = match filepath {
601607 Some ( fp) => fp,
602608 None => {
@@ -620,40 +626,91 @@ pub async fn run_submit_tui(filepath: Option<String>, cli_id: String) -> Result<
620626 ) ) ;
621627 }
622628
629+ // Perform direct submission if all required parameters are provided via CLI
630+ if let ( Some ( gpu_flag) , Some ( leaderboard_flag) , Some ( mode_flag) ) = ( & gpu, & leaderboard, & mode) {
631+ // Read file content
632+ let mut file = File :: open ( & file_to_submit) ?;
633+ let mut file_content = String :: new ( ) ;
634+ file. read_to_string ( & mut file_content) ?;
635+
636+ // Create client and submit directly
637+ let client = service:: create_client ( Some ( cli_id) ) ?;
638+ println ! ( "Submitting solution directly with:" ) ;
639+ println ! ( " File: {}" , file_to_submit) ;
640+ println ! ( " Leaderboard: {}" , leaderboard_flag) ;
641+ println ! ( " GPU: {}" , gpu_flag) ;
642+ println ! ( " Mode: {}" , mode_flag) ;
643+
644+ // Make the submission
645+ let result = service:: submit_solution (
646+ & client,
647+ & file_to_submit,
648+ & file_content,
649+ leaderboard_flag,
650+ gpu_flag,
651+ mode_flag
652+ ) . await ?;
653+
654+ utils:: display_ascii_art ( ) ;
655+ println ! ( "{}" , result) ;
656+ return Ok ( ( ) ) ;
657+ }
658+
623659 let mut app = App :: new ( & file_to_submit, cli_id) ;
624- app. initialize_with_directives ( directives) ;
625660
661+ // Override directives with CLI flags if provided
662+ if let Some ( gpu_flag) = gpu {
663+ app. selected_gpu = Some ( gpu_flag) ;
664+ }
665+ if let Some ( leaderboard_flag) = leaderboard {
666+ app. selected_leaderboard = Some ( leaderboard_flag) ;
667+ }
668+ if let Some ( mode_flag) = mode {
669+ app. selected_submission_mode = Some ( mode_flag) ;
670+ // Skip to submission if we have all required fields
671+ if app. selected_gpu . is_some ( ) && app. selected_leaderboard . is_some ( ) {
672+ app. modal_state = ModelState :: WaitingForResult ;
673+ }
674+ }
675+
676+ // If no CLI flags, use directives
677+ if app. selected_gpu . is_none ( ) && app. selected_leaderboard . is_none ( ) {
678+ app. initialize_with_directives ( directives) ;
679+ }
680+
681+ // Spawn the initial task based on the starting state BEFORE setting up the TUI
682+ // If spawning fails here, we just return the error directly without TUI cleanup.
683+ match app. modal_state {
684+ ModelState :: LeaderboardSelection => {
685+ if let Err ( e) = app. spawn_load_leaderboards ( ) {
686+ return Err ( anyhow ! ( "Error starting leaderboard fetch: {}" , e) ) ;
687+ }
688+ }
689+ ModelState :: GpuSelection => {
690+ if let Err ( e) = app. spawn_load_gpus ( ) {
691+ return Err ( anyhow ! ( "Error starting GPU fetch: {}" , e) ) ;
692+ }
693+ }
694+ ModelState :: WaitingForResult => {
695+ // This state occurs when all flags (gpu, leaderboard, mode) are provided
696+ if let Err ( e) = app. spawn_submit_solution ( ) {
697+ return Err ( anyhow ! ( "Error starting submission: {}" , e) ) ;
698+ }
699+ }
700+ _ => {
701+ // Other states like SubmissionModeSelection shouldn't be the *initial* state
702+ // unless there's a logic error elsewhere. We'll proceed to TUI.
703+ }
704+ }
705+
706+ // Now, set up the TUI
626707 enable_raw_mode ( ) ?;
627708 let mut stdout = io:: stdout ( ) ;
628709 crossterm:: execute!( stdout, EnterAlternateScreen ) ?;
629710 let backend = CrosstermBackend :: new ( stdout) ;
630711 let mut terminal = Terminal :: new ( backend) ?;
631712
632- if app. modal_state == ModelState :: LeaderboardSelection {
633- if let Err ( e) = app. spawn_load_leaderboards ( ) {
634- // Cleanup terminal before exiting on initial load error
635- disable_raw_mode ( ) ?;
636- crossterm:: execute!(
637- terminal. backend_mut( ) ,
638- crossterm:: terminal:: LeaveAlternateScreen
639- ) ?;
640- terminal. show_cursor ( ) ?;
641- return Err ( anyhow ! ( "Error starting leaderboard fetch: {}" , e) ) ;
642- }
643- } else if app. modal_state == ModelState :: GpuSelection {
644- if let Err ( e) = app. spawn_load_gpus ( ) {
645- // Cleanup terminal before exiting on initial load error
646- disable_raw_mode ( ) ?;
647- crossterm:: execute!(
648- terminal. backend_mut( ) ,
649- crossterm:: terminal:: LeaveAlternateScreen
650- ) ?;
651- terminal. show_cursor ( ) ?;
652- return Err ( anyhow ! ( "Error starting GPU fetch: {}" , e) ) ;
653- }
654- }
655-
656- // Main application loop
713+ // Main application loop - this remains largely the same
657714 while !app. should_quit {
658715 terminal. draw ( |f| ui ( & app, f) ) ?;
659716
0 commit comments