rustyrails_cli/
generate.rs

1use std::{fs, path::PathBuf};
2
3use cargo_generate::{generate, GenerateArgs, TemplatePath, Vcs};
4
5use crate::template::Starter;
6
7/// A generator form the git repo
8///
9/// # Errors
10/// 1. when `folder_name` does not exist or A non-final component in path is not
11///    a directory
12/// 2. When has an error generating the git repository
13///
14/// # Examples
15///
16/// ```rust
17/// use std::path::PathBuf;
18/// use rustyrails_cli::template::Starter;
19/// let path = PathBuf::from(".");
20/// rustyrails_cli::generate::demo_site(&Starter::Saas,&path, "demo-website", None);
21/// ```
22pub fn demo_site(
23    starter_template: &Starter,
24    path: &PathBuf,
25    folder_name: &str,
26    define: Option<Vec<String>>,
27) -> eyre::Result<PathBuf> {
28    let define = define.unwrap_or_default();
29
30    let args = GenerateArgs {
31        destination: Some(fs::canonicalize(path)?),
32        name: Some(folder_name.to_string()),
33        vcs: Some(Vcs::Git),
34        template_path: TemplatePath {
35            git: Some(starter_template.git_url()),
36            ..TemplatePath::default()
37        },
38        define,
39        ..GenerateArgs::default()
40    };
41
42    generate(args).map_err(|e| eyre::eyre!(e))
43}