diff --git a/src/cmd/mod.rs b/src/cmd/mod.rs index 617bfad..2ff54f8 100644 --- a/src/cmd/mod.rs +++ b/src/cmd/mod.rs @@ -51,10 +51,14 @@ pub struct Cli { /// Optional: Directly specify the leaderboard (e.g., "fp8") #[arg(long)] pub leaderboard: Option, - + /// Optional: Specify submission mode (test, benchmark, leaderboard, profile) #[arg(long)] pub mode: Option, + + // Optional: Specify output file + #[arg(short, long)] + pub output: Option, } #[derive(Subcommand, Debug)] @@ -88,6 +92,10 @@ enum Commands { /// Optional: Specify submission mode (test, benchmark, leaderboard, profile) #[arg(long)] mode: Option, + + // Optional: Specify output file + #[arg(short, long)] + output: Option, }, } @@ -107,7 +115,13 @@ pub async fn execute(cli: Cli) -> Result<()> { }; auth::run_auth(false, provider_str).await } - Some(Commands::Submit { filepath, gpu, leaderboard, mode }) => { + Some(Commands::Submit { + filepath, + gpu, + leaderboard, + mode, + output, + }) => { let config = load_config()?; let cli_id = config.cli_id.ok_or_else(|| { anyhow!( @@ -116,7 +130,7 @@ pub async fn execute(cli: Cli) -> Result<()> { .map_or_else(|_| "unknown path".to_string(), |p| p.display().to_string()) ) })?; - + // Use filepath from Submit command first, fallback to top-level filepath let final_filepath = filepath.or(cli.filepath); submit::run_submit_tui( @@ -125,6 +139,7 @@ pub async fn execute(cli: Cli) -> Result<()> { leaderboard, // From Submit command mode, // From Submit command cli_id, + output, // From Submit command ) .await } @@ -136,7 +151,7 @@ pub async fn execute(cli: Cli) -> Result<()> { popcorn-cli submit [--gpu GPU] [--leaderboard LEADERBOARD] [--mode MODE] FILEPATH" )); } - + // Handle the case where only a filepath is provided (for backward compatibility) if let Some(top_level_filepath) = cli.filepath { let config = load_config()?; @@ -147,7 +162,7 @@ pub async fn execute(cli: Cli) -> Result<()> { .map_or_else(|_| "unknown path".to_string(), |p| p.display().to_string()) ) })?; - + // Run TUI with only filepath, no other options submit::run_submit_tui( Some(top_level_filepath), @@ -155,6 +170,7 @@ pub async fn execute(cli: Cli) -> Result<()> { None, // No leaderboard option None, // No mode option cli_id, + None, // No output option ) .await } else { diff --git a/src/cmd/submit.rs b/src/cmd/submit.rs index 83411be..4b8f04c 100644 --- a/src/cmd/submit.rs +++ b/src/cmd/submit.rs @@ -523,6 +523,7 @@ pub async fn run_submit_tui( leaderboard: Option, mode: Option, cli_id: String, + output: Option, ) -> Result<()> { let file_to_submit = match filepath { Some(fp) => fp, @@ -630,6 +631,17 @@ pub async fn run_submit_tui( result_text = content.to_string(); } + // write to file if output is specified + if let Some(output_path) = output { + // create parent directories if they don't exist + if let Some(parent) = Path::new(&output_path).parent() { + std::fs::create_dir_all(parent) + .map_err(|e| anyhow!("Failed to create directories for {}: {}", output_path, e))?; + } + std::fs::write(&output_path, &result_text) + .map_err(|e| anyhow!("Failed to write result to file {}: {}", output_path, e))?; + } + let state = &mut app.result_page_state; let mut result_page = ResultPage::new(result_text.clone(), state);