use std::process::ExitCode;

use eyre::Context;

const USAGE: &str = r#"
bake [target...] [-- [args-for-last-target...]]
"#;

fn print_usage() {
	println!("{USAGE}");
}

fn go() -> eyre::Result<()> {
	let contents = match std::fs::read_to_string("build.bake") {
		Ok(v) => v,
		Err(e) => match e.kind() {
			std::io::ErrorKind::NotFound => {
				println!("build.bake not present in current directory");
				return Ok(());
			},
			_ => {
				return Err(e).wrap_err("Failed to read contents of build.bake")
			},
		},
	};

	let mut graph = bake::build_graph_from_str(&contents)?;
	bake::execute_graph(&graph)?;

	Ok(())
}

fn main() -> eyre::Result<()> {
	go()
}
