1use crate::commands;
2use crate::settings::toml::TargetType;
3
4use anyhow::Result;
5
6pub fn generate(
7 name: String,
8 site: bool,
9 template: Option<String>,
10 target_type: Option<TargetType>,
11) -> Result<()> {
12 const DEFAULT_TEMPLATE: &str = "https://github.com/cloudflare/worker-template";
13 const RUST_TEMPLATE: &str = "https://github.com/cloudflare/rustwasm-worker-template";
14 const SITES_TEMPLATE: &str = "https://github.com/cloudflare/worker-sites-template";
15
16 let template = if site {
17 SITES_TEMPLATE
18 } else if let Some(template) = template.as_deref() {
19 template
20 } else if let Some(TargetType::Rust) = target_type {
21 RUST_TEMPLATE
22 } else {
23 DEFAULT_TEMPLATE
24 };
25
26 log::info!(
27 "Generate command called with template {}, and name {}",
28 template,
29 name
30 );
31
32 commands::generate(&name, template, target_type, site)
33}