1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
use std::{ path::PathBuf, }; use failure::Fail; use crate::project::{Project, ProjectInitError}; #[derive(Debug, Fail)] pub enum InitError { #[fail(display = "Invalid project kind '{}', valid kinds are 'place' and 'model'", _0)] InvalidKind(String), #[fail(display = "Project init error: {}", _0)] ProjectInitError(#[fail(cause)] ProjectInitError) } impl_from!(InitError { ProjectInitError => ProjectInitError, }); #[derive(Debug)] pub struct InitOptions<'a> { pub fuzzy_project_path: PathBuf, pub kind: Option<&'a str>, } pub fn init(options: &InitOptions) -> Result<(), InitError> { let (project_path, project_kind) = match options.kind { Some("place") | None => { let path = Project::init_place(&options.fuzzy_project_path)?; (path, "place") }, Some("model") => { let path = Project::init_model(&options.fuzzy_project_path)?; (path, "model") }, Some(invalid) => return Err(InitError::InvalidKind(invalid.to_string())), }; println!("Created new {} project file at {}", project_kind, project_path.display()); Ok(()) }