Skip to content
Open
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
8 changes: 5 additions & 3 deletions src/cmd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ enum Commands {
},
Submit {
filepath: Option<String>,
#[arg(short, long)]
output: Option<PathBuf>,
},
}

Expand All @@ -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!(
Expand All @@ -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()?;
Expand All @@ -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
}
}
}
9 changes: 6 additions & 3 deletions src/cmd/submit.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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<String>, cli_id: String) -> Result<()> {
pub async fn run_submit_tui(filepath: Option<String>, cli_id: String, output: Option<PathBuf>) -> Result<()> {
let file_to_submit = match filepath {
Some(fp) => fp,
None => {
Expand Down Expand Up @@ -684,6 +684,9 @@ pub async fn run_submit_tui(filepath: Option<String>, cli_id: String) -> Result<

if let Some(status) = app.final_status {
println!("{}", status);
if let Some(output) = output {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe make this support creating directories as well? I.e. -o outputs/test.json would create outputs if not exist?

fs::write(output, status.as_bytes())?;
}
} else {
println!("Operation cancelled."); // Or some other default message if quit early
}
Expand Down