Skip to main content

start_command/
log_uploader.rs

1//! Helpers for uploading tracked execution logs.
2
3use std::path::Path;
4
5use crate::execution_store::ExecutionStore;
6use crate::failure_handler::upload_log_interactive_with_options;
7
8/// Upload the log for a stored execution by UUID or session name.
9pub fn upload_execution_log(
10    store: Option<&ExecutionStore>,
11    identifier: &str,
12) -> Result<i32, String> {
13    upload_execution_log_with_options(store, identifier, false, false)
14}
15
16/// Upload a stored log with an explicit sanitization opt-out and diagnostics.
17pub fn upload_execution_log_with_options(
18    store: Option<&ExecutionStore>,
19    identifier: &str,
20    no_sanitize: bool,
21    verbose: bool,
22) -> Result<i32, String> {
23    let store = store.ok_or_else(|| "Execution tracking is disabled.".to_string())?;
24    let record = store.get(identifier).ok_or_else(|| {
25        format!(
26            "No execution found with UUID or session name: {}",
27            identifier
28        )
29    })?;
30
31    if record.log_path.is_empty() {
32        return Err("Execution record does not have a log path.".to_string());
33    }
34
35    if !Path::new(&record.log_path).exists() {
36        return Err(format!("Log file not found: {}", record.log_path));
37    }
38
39    upload_log_interactive_with_options(&record.log_path, no_sanitize, verbose)
40}