use crate::error::Result;
use std::env;
use std::path::PathBuf;
use tempfile::TempDir;
pub fn setup_example_storage() -> Result<PathBuf> {
let temp_dir = TempDir::new()
.map_err(|e| crate::error::Error::Storage(format!("Failed to create temp dir: {}", e)))?;
let tap_dir = temp_dir.path().to_path_buf();
env::set_var("TAP_HOME", &tap_dir);
let keys_path = tap_dir.join("keys.json");
println!("Using temporary storage at: {:?}", tap_dir);
println!("(This protects your production ~/.tap directory)");
println!();
std::mem::forget(temp_dir);
Ok(keys_path)
}
pub fn setup_example_tap_root() -> Result<PathBuf> {
let temp_dir = TempDir::new()
.map_err(|e| crate::error::Error::Storage(format!("Failed to create temp dir: {}", e)))?;
let root_dir = temp_dir.path().to_path_buf();
let tap_dir = root_dir.join(".tap");
std::fs::create_dir_all(&tap_dir).map_err(|e| {
crate::error::Error::Storage(format!("Failed to create .tap directory: {}", e))
})?;
env::set_var("TAP_TEST_DIR", &root_dir);
println!("Using temporary TAP root at: {:?}", root_dir);
println!("TAP directory: {:?}", tap_dir);
println!("(This protects your production ~/.tap directory)");
println!();
std::mem::forget(temp_dir);
Ok(tap_dir)
}
pub fn print_temp_storage_notice() {
println!();
println!("Note: This example used temporary storage.");
println!("Your production ~/.tap directory was not affected.");
}