52 lines
1.3 KiB
Rust
52 lines
1.3 KiB
Rust
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(),
|
|
),
|
|
}
|
|
}
|