use std::fs::{create_dir_all, File}; use std::io::prelude::*; use std::path::Path; use tempfile::{tempdir, TempDir}; /// Create a basic project #[allow(dead_code)] pub fn create_project(name: &str) -> Result> { let root_dir = tempdir()?; let folder = root_dir.path(); // Write a configuration File let mut cfg_file = File::create(folder.join("orcs.toml"))?; let cfg_data = format!("global.params.project = \"{}\"", name); cfg_file.write_all(cfg_data.as_bytes())?; Ok(root_dir) } /// Create a basic service #[allow(dead_code)] pub fn create_service(folder: &Path, name: &str) -> Result<(), Box> { // Create a path for the service let service_path = folder.join("srv").join(name); create_dir_all(&service_path)?; // Write the service file let mut file = File::create(service_path.join("orcs.toml"))?; let data = "stages.build.actions = [\"echo 'Hello world'\"]"; file.write_all(data.as_bytes())?; Ok(()) } /// Create a basic recipe #[allow(dead_code)] pub fn create_recipe(folder: &Path, name: &str) -> Result<(), Box> { let recipe_path = folder.join("rcp"); create_dir_all(&recipe_path)?; let mut file = File::create(recipe_path.join(format!("{}.toml", name)))?; let data = "stages.build.actions = [\"echo 'Hello world'\"]"; file.write_all(data.as_bytes())?; Ok(()) }