Skip to main content

cup_cli/plugin/
plugin.rs

1use crate::{cli::CreateProject, debug, write_template};
2use std::io::Write;
3
4#[derive(Debug, Clone, Default)]
5pub struct Module {}
6
7impl CreateProject for Module {
8    fn create_project(&self, name: &str, path: &std::path::PathBuf) -> anyhow::Result<()> {
9        debug!("Creating module(plugin) project: {name:?} at {path:?}");
10
11        // Cup.toml
12        {
13            let path = path.join("Cup.toml");
14            let mut file = fs_err::File::create(path)?;
15            write_template!(file, "templates/Cup.toml" => [
16                NAME = name.to_string();
17                TYPE = "module".to_string();
18            ])?;
19        }
20
21        // .gitignore
22        {
23            let path = path.join(".gitignore");
24            let mut file = fs_err::File::create(path)?;
25            write_template!(file, "templates/gitignore")?;
26        }
27
28        fs_err::create_dir(path.join("src"))?;
29        //  src/lib.cpp
30        {
31            let path = path.join("src/lib.cpp");
32            let mut file = fs_err::File::create(path)?;
33            write_template!(file, "templates/lib.cpp")?;
34        }
35
36        Ok(())
37    }
38}