utz_build_cli/cmd/
gen_preset.rs1use std::path::PathBuf;
12
13use utz_build::Config;
14use utz_build::presets::{self, Recipe};
15
16#[derive(clap::Args)]
17pub struct Args {
18 preset: Option<String>,
20 #[arg(long, short, requires = "preset")]
23 out: Option<PathBuf>,
24}
25
26pub fn run(args: Args) -> utz_build::Result<()> {
30 if let Some(name) = args.preset {
31 let recipe = presets::by_name(&name).ok_or_else(|| {
32 let known = presets::ALL.map(|recipe| recipe.name).join("|");
33 utz_build::Error::Msg(format!("unknown preset {name:?}: use {known}"))
34 })?;
35 generate(recipe, args.out)
36 } else {
37 for recipe in &presets::ALL {
38 generate(recipe, None)?;
39 }
40 Ok(())
41 }
42}
43
44fn generate(recipe: &Recipe, out: Option<PathBuf>) -> utz_build::Result<()> {
47 let out = if let Some(out) = out {
48 out
49 } else {
50 let dir = PathBuf::from(format!("utz_data_{}", recipe.name.replace('-', "_")));
51 if !dir.is_dir() {
52 return Err(utz_build::Error::Msg(format!(
53 "default output {}/data/ expects the μTZ checkout root as the \
54 current directory; pass --out",
55 dir.display()
56 )));
57 }
58 dir.join("data").join(format!("{}.utz", recipe.name))
59 };
60 let path = Config::from(recipe).out_path(out).generate()?;
61 println!("wrote {}", path.display());
62 Ok(())
63}