diff --git a/src/cmd/mod.rs b/src/cmd/mod.rs index 4fde558..a6d51a1 100644 --- a/src/cmd/mod.rs +++ b/src/cmd/mod.rs @@ -63,6 +63,8 @@ enum Commands { }, Submit { filepath: Option, + #[arg(short, long)] + output: Option, }, } @@ -82,7 +84,7 @@ pub async fn execute(cli: Cli) -> Result<()> { }; auth::run_auth(false, provider_str).await } - Some(Commands::Submit { filepath }) => { + Some(Commands::Submit { filepath, output }) => { let config = load_config()?; let cli_id = config.cli_id.ok_or_else(|| { anyhow!( @@ -92,7 +94,7 @@ pub async fn execute(cli: Cli) -> Result<()> { ) })?; let file_to_submit = filepath.or(cli.filepath); - submit::run_submit_tui(file_to_submit, cli_id).await + submit::run_submit_tui(file_to_submit, cli_id, output).await } None => { let config = load_config()?; @@ -103,7 +105,7 @@ pub async fn execute(cli: Cli) -> Result<()> { .map_or_else(|_| "unknown path".to_string(), |p| p.display().to_string()) ) })?; - submit::run_submit_tui(cli.filepath, cli_id).await + submit::run_submit_tui(cli.filepath, cli_id, None).await } } } diff --git a/src/cmd/submit.rs b/src/cmd/submit.rs index 408654b..ea3eacd 100644 --- a/src/cmd/submit.rs +++ b/src/cmd/submit.rs @@ -1,6 +1,6 @@ -use std::fs::File; +use std::fs::{self, File}; use std::io::{self, Read}; -use std::path::Path; +use std::path::{Path, PathBuf}; use anyhow::{anyhow, Result}; use crossterm::event::{self, Event, KeyCode, KeyEvent, KeyEventKind, KeyModifiers}; @@ -596,7 +596,7 @@ fn centered_rect(percent_x: u16, percent_y: u16, r: Rect) -> Rect { .split(popup_layout[1])[1] } -pub async fn run_submit_tui(filepath: Option, cli_id: String) -> Result<()> { +pub async fn run_submit_tui(filepath: Option, cli_id: String, output: Option) -> Result<()> { let file_to_submit = match filepath { Some(fp) => fp, None => { @@ -684,6 +684,9 @@ pub async fn run_submit_tui(filepath: Option, cli_id: String) -> Result< if let Some(status) = app.final_status { println!("{}", status); + if let Some(output) = output { + fs::write(output, status.as_bytes())?; + } } else { println!("Operation cancelled."); // Or some other default message if quit early }