Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions src/cmd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,14 @@ pub struct Cli {
/// Optional: Directly specify the leaderboard (e.g., "fp8")
#[arg(long)]
pub leaderboard: Option<String>,

/// Optional: Specify submission mode (test, benchmark, leaderboard, profile)
#[arg(long)]
pub mode: Option<String>,

// Optional: Specify output file
#[arg(short, long)]
pub output: Option<String>,
}

#[derive(Subcommand, Debug)]
Expand Down Expand Up @@ -88,6 +92,10 @@ enum Commands {
/// Optional: Specify submission mode (test, benchmark, leaderboard, profile)
#[arg(long)]
mode: Option<String>,

// Optional: Specify output file
#[arg(short, long)]
output: Option<String>,
},
}

Expand All @@ -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!(
Expand All @@ -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(
Expand All @@ -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
}
Expand All @@ -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()?;
Expand All @@ -147,14 +162,15 @@ 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),
None, // No GPU option
None, // No leaderboard option
None, // No mode option
cli_id,
None, // No output option
)
.await
} else {
Expand Down
12 changes: 12 additions & 0 deletions src/cmd/submit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,7 @@ pub async fn run_submit_tui(
leaderboard: Option<String>,
mode: Option<String>,
cli_id: String,
output: Option<String>,
) -> Result<()> {
let file_to_submit = match filepath {
Some(fp) => fp,
Expand Down Expand Up @@ -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);
Expand Down
Loading