feat: Show error if no clusters are found in repo

This commit is contained in:
2026-03-31 05:17:14 +02:00
parent e4d39de2f0
commit a7578a6b16
3 changed files with 21 additions and 4 deletions
+19 -4
View File
@@ -6,15 +6,26 @@ use crete::cluster::get_clusters;
use crete::environment::PathEnvironment;
use crete::set_repo_path;
use minijinja::context;
use thiserror::Error;
use crate::cli::{Cli, Commands, GlobalOpts};
fn generate(opts: &GlobalOpts) {
#[derive(Debug, Error)]
enum Error {
#[error("No clusters where found")]
NoClustersFound,
}
fn generate(opts: &GlobalOpts) -> Result<(), Error> {
set_repo_path(&opts.repo);
let patch_env = PathEnvironment::new_patches();
let clusters = get_clusters(&patch_env);
if clusters.is_empty() {
return Err(Error::NoClustersFound);
}
let path = opts.repo.join("rendered");
if path.exists() {
std::fs::remove_dir_all(&path).unwrap();
@@ -34,18 +45,22 @@ fn generate(opts: &GlobalOpts) {
std::fs::write(path.join(template_name), content).unwrap();
}
Ok(())
}
fn main() {
fn main() -> Result<(), Error> {
let cli = Cli::parse();
match cli.command {
Commands::Generate => generate(&cli.global_opts),
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(),
),
}
};
Ok(())
}