thot_cli/commands/project/
new.rs

1use crate::result::Result;
2use clap::Args;
3use std::env;
4use std::path::{Path, PathBuf};
5use thot_local::project::project;
6
7#[derive(Debug, Args)]
8pub struct NewArgs {
9    name: String,
10
11    #[clap(short, long, parse(from_os_str))]
12    root: Option<PathBuf>,
13}
14
15/// Creates a new Thot project.
16pub fn main(args: NewArgs, verbose: bool) -> Result {
17    // get root path
18    let root = match args.root {
19        Some(p) => p,
20        None => env::current_dir()?,
21    };
22
23    let root = root.join(Path::new(&args.name));
24
25    // create project
26    if let Err(err) = project::new(root.as_path()) {
27        return Err(err.into());
28    };
29
30    // set project properties
31    // project and root container: creator, name, permissions, lid
32
33    if verbose {
34        println!("New project created at {:?}", &root);
35    }
36
37    Ok(())
38}
39
40#[cfg(test)]
41#[path = "./new_test.rs"]
42mod new_test;