Skip to main content

cup_cli/plugin/
hdr.rs

1use crate::{cli::CreateProject, debug, write_template};
2use std::io::Write;
3
4#[derive(Debug, Clone, Default)]
5pub struct HeaderOnly {}
6
7impl CreateProject for HeaderOnly {
8    fn create_project(&self, name: &str, path: &std::path::PathBuf) -> anyhow::Result<()> {
9        debug!("Creating header-only 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 = "header-only".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("include"))?;
29        //  include/header.h
30        {
31            let path = path.join("include").join(format!("{}.h", name));
32            let mut file = fs_err::File::create(path)?;
33            write_template!(file, "templates/header.h")?;
34        }
35
36        Ok(())
37    }
38}