Skip to main content

camel_cli/template/
mod.rs

1pub mod authorization_policy;
2pub mod bean;
3pub mod embedded;
4pub mod processor;
5
6use std::fmt;
7
8#[derive(Clone, Copy, Debug, Default, PartialEq, clap::ValueEnum)]
9pub enum ProfileLayout {
10    Simple,
11    #[default]
12    Env,
13}
14
15impl fmt::Display for ProfileLayout {
16    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
17        match self {
18            ProfileLayout::Simple => write!(f, "simple"),
19            ProfileLayout::Env => write!(f, "env"),
20        }
21    }
22}
23
24pub struct TemplateFile {
25    pub path: String,
26    pub content: String,
27}
28
29pub struct TemplateContext {
30    pub project_name: String,
31    pub profile_layout: ProfileLayout,
32}
33
34pub trait TemplateProvider {
35    fn name(&self) -> &str;
36    fn files(&self, ctx: &TemplateContext)
37    -> Result<Vec<TemplateFile>, Box<dyn std::error::Error>>;
38}
39
40pub fn cargo_toml(plugin_name: &str) -> String {
41    format!(
42        "[package]\nname = \"{plugin_name}\"\nversion = \"0.1.0\"\nedition = \"2021\"\n\n[workspace]\n\n[lib]\ncrate-type = [\"cdylib\"]\n\n[dependencies]\nwit-bindgen = \"0.57\"\n"
43    )
44}
45
46pub fn plugin_toml(plugin_name: &str, plugin_type: &str) -> String {
47    format!(
48        "name = \"{plugin_name}\"\nversion = \"0.1.0\"\ntype = \"{plugin_type}\"\nentry = \"{plugin_name}.wasm\"\n"
49    )
50}
51
52pub fn readme_md(plugin_name: &str, plugin_type: &str) -> String {
53    format!(
54        "# {plugin_name}\n\nWASM {plugin_type} plugin for Camel.\n\n## Build\n\n```bash\ncamel plugin build\n```\n\n## Files\n\n- `src/lib.rs`: plugin entrypoint implementing {plugin_type} Guest methods\n- `wit/`: WIT definitions used for guest bindings generation\n- `Camel.plugin.toml`: plugin metadata for Camel\n"
55    )
56}
57
58pub fn gitignore() -> &'static str {
59    "target\nplugins/\n"
60}
61
62pub fn to_pascal_case(name: &str) -> String {
63    name.split(|c: char| !c.is_ascii_alphanumeric())
64        .filter(|part| !part.is_empty())
65        .map(|part| {
66            let mut chars = part.chars();
67            let mut out = String::new();
68            if let Some(first) = chars.next() {
69                out.extend(first.to_uppercase());
70                out.extend(chars.flat_map(|c| c.to_lowercase()));
71            }
72            out
73        })
74        .collect()
75}