aurora-modules 0.1.0

Git, filesystem, system, network, archive, docker, unix, crypto, calculator, QR, color, timer, notes, clipboard, and text processing modules
Documentation
use aurora_core::{AuroraResult, Pipeline, Value};
use std::fs;
use std::io::Write;
use std::path::PathBuf;
use std::time::{SystemTime, UNIX_EPOCH};

fn notes_path() -> PathBuf {
    let home = std::env::var("HOME").unwrap_or_else(|_| "/tmp".into());
    PathBuf::from(home).join(".cache").join("aurora").join("notes.txt")
}

fn ensure_dir(path: &PathBuf) -> AuroraResult<()> {
    if let Some(parent) = path.parent() {
        fs::create_dir_all(parent)
            .map_err(|e| aurora_core::AuroraError::Io(e))?;
    }
    Ok(())
}

pub fn note_add(text: &[String]) -> AuroraResult<Pipeline> {
    let path = notes_path();
    ensure_dir(&path)?;

    let timestamp = SystemTime::now()
        .duration_since(UNIX_EPOCH)
        .map(|d| d.as_secs())
        .unwrap_or(0);

    let line = format!("[{}] {}\n", timestamp, text.join(" "));

    let mut file = fs::OpenOptions::new()
        .create(true)
        .append(true)
        .open(&path)
        .map_err(|e| aurora_core::AuroraError::Io(e))?;

    file.write_all(line.as_bytes())
        .map_err(|e| aurora_core::AuroraError::Io(e))?;

    Ok(Pipeline::table(
        vec!["action".into(), "note".into(), "file".into()],
        vec![vec![
            Value::String("add".into()),
            Value::String(text.join(" ")),
            Value::String(path.to_string_lossy().into()),
        ]],
    ))
}