Skip to content

Commit b9d7994

Browse files
authored
Merge pull request #22 from gau-nernst/feat/output
feat: add output flag
2 parents 4ac8ffd + 5a296e2 commit b9d7994

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

src/cmd/mod.rs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,14 @@ pub struct Cli {
5151
/// Optional: Directly specify the leaderboard (e.g., "fp8")
5252
#[arg(long)]
5353
pub leaderboard: Option<String>,
54-
54+
5555
/// Optional: Specify submission mode (test, benchmark, leaderboard, profile)
5656
#[arg(long)]
5757
pub mode: Option<String>,
58+
59+
// Optional: Specify output file
60+
#[arg(short, long)]
61+
pub output: Option<String>,
5862
}
5963

6064
#[derive(Subcommand, Debug)]
@@ -88,6 +92,10 @@ enum Commands {
8892
/// Optional: Specify submission mode (test, benchmark, leaderboard, profile)
8993
#[arg(long)]
9094
mode: Option<String>,
95+
96+
// Optional: Specify output file
97+
#[arg(short, long)]
98+
output: Option<String>,
9199
},
92100
}
93101

@@ -107,7 +115,13 @@ pub async fn execute(cli: Cli) -> Result<()> {
107115
};
108116
auth::run_auth(false, provider_str).await
109117
}
110-
Some(Commands::Submit { filepath, gpu, leaderboard, mode }) => {
118+
Some(Commands::Submit {
119+
filepath,
120+
gpu,
121+
leaderboard,
122+
mode,
123+
output,
124+
}) => {
111125
let config = load_config()?;
112126
let cli_id = config.cli_id.ok_or_else(|| {
113127
anyhow!(
@@ -116,7 +130,7 @@ pub async fn execute(cli: Cli) -> Result<()> {
116130
.map_or_else(|_| "unknown path".to_string(), |p| p.display().to_string())
117131
)
118132
})?;
119-
133+
120134
// Use filepath from Submit command first, fallback to top-level filepath
121135
let final_filepath = filepath.or(cli.filepath);
122136
submit::run_submit_tui(
@@ -125,6 +139,7 @@ pub async fn execute(cli: Cli) -> Result<()> {
125139
leaderboard, // From Submit command
126140
mode, // From Submit command
127141
cli_id,
142+
output, // From Submit command
128143
)
129144
.await
130145
}
@@ -136,7 +151,7 @@ pub async fn execute(cli: Cli) -> Result<()> {
136151
popcorn-cli submit [--gpu GPU] [--leaderboard LEADERBOARD] [--mode MODE] FILEPATH"
137152
));
138153
}
139-
154+
140155
// Handle the case where only a filepath is provided (for backward compatibility)
141156
if let Some(top_level_filepath) = cli.filepath {
142157
let config = load_config()?;
@@ -147,14 +162,15 @@ pub async fn execute(cli: Cli) -> Result<()> {
147162
.map_or_else(|_| "unknown path".to_string(), |p| p.display().to_string())
148163
)
149164
})?;
150-
165+
151166
// Run TUI with only filepath, no other options
152167
submit::run_submit_tui(
153168
Some(top_level_filepath),
154169
None, // No GPU option
155170
None, // No leaderboard option
156171
None, // No mode option
157172
cli_id,
173+
None, // No output option
158174
)
159175
.await
160176
} else {

src/cmd/submit.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,7 @@ pub async fn run_submit_tui(
523523
leaderboard: Option<String>,
524524
mode: Option<String>,
525525
cli_id: String,
526+
output: Option<String>,
526527
) -> Result<()> {
527528
let file_to_submit = match filepath {
528529
Some(fp) => fp,
@@ -630,6 +631,17 @@ pub async fn run_submit_tui(
630631
result_text = content.to_string();
631632
}
632633

634+
// write to file if output is specified
635+
if let Some(output_path) = output {
636+
// create parent directories if they don't exist
637+
if let Some(parent) = Path::new(&output_path).parent() {
638+
std::fs::create_dir_all(parent)
639+
.map_err(|e| anyhow!("Failed to create directories for {}: {}", output_path, e))?;
640+
}
641+
std::fs::write(&output_path, &result_text)
642+
.map_err(|e| anyhow!("Failed to write result to file {}: {}", output_path, e))?;
643+
}
644+
633645
let state = &mut app.result_page_state;
634646

635647
let mut result_page = ResultPage::new(result_text.clone(), state);

0 commit comments

Comments
 (0)