feat: Initial rewrite of python render tool

This commit is contained in:
2026-03-16 03:14:33 +01:00
commit e4d39de2f0
24 changed files with 4453 additions and 0 deletions
+51
View File
@@ -0,0 +1,51 @@
mod cli;
use clap::{CommandFactory, Parser};
use clap_complete::{Shell, generate as generate_complete};
use crete::cluster::get_clusters;
use crete::environment::PathEnvironment;
use crete::set_repo_path;
use minijinja::context;
use crate::cli::{Cli, Commands, GlobalOpts};
fn generate(opts: &GlobalOpts) {
set_repo_path(&opts.repo);
let patch_env = PathEnvironment::new_patches();
let clusters = get_clusters(&patch_env);
let path = opts.repo.join("rendered");
if path.exists() {
std::fs::remove_dir_all(&path).unwrap();
}
std::fs::create_dir(&path).unwrap();
let template_env = PathEnvironment::new_templates(&opts.repo);
for template_name in &template_env {
let template = template_env.get_template(&template_name).unwrap();
let content = template
.render(context! {
clusters,
root => opts.repo
})
.unwrap();
std::fs::write(path.join(template_name), content).unwrap();
}
}
fn main() {
let cli = Cli::parse();
match cli.command {
Commands::Generate => generate(&cli.global_opts),
Commands::ShellCompletions => generate_complete(
Shell::from_env().unwrap_or(Shell::Bash),
&mut Cli::command(),
"crete",
&mut std::io::stdout(),
),
}
}