#![allow(clippy::format_push_string)]
use std::path::Path;
use crate::deployment::error::DeploymentError;
pub(super) fn to_camel_suffix(name: &str) -> String {
let mut result = String::new();
let mut capitalize_next = false;
for ch in name.chars() {
if ch == '_' || ch == '-' {
capitalize_next = true;
} else if capitalize_next {
result.push(ch.to_ascii_uppercase());
capitalize_next = false;
} else {
result.push(ch);
}
}
result
}
pub(super) fn is_go_identifier(s: &str) -> bool {
let mut chars = s.chars();
match chars.next() {
Some(c) if c.is_ascii_alphabetic() || c == '_' => {}
_ => return false,
}
chars.all(|c| c.is_ascii_alphanumeric() || c == '_')
}
pub(super) fn safe_template_lookup(base: &str, key: &str) -> String {
if is_go_identifier(key) {
format!("{base}.{key}")
} else {
format!("(index {base} \"{key}\")")
}
}
pub(super) fn write_file(path: impl AsRef<Path>, content: &str) -> Result<(), DeploymentError> {
let path = path.as_ref();
std::fs::write(path, content).map_err(|e| DeploymentError::WriteFile {
path: path.display().to_string(),
source: e,
})
}