use std::path::PathBuf; use anyhow::{anyhow, Context, Result}; use clap::Parser; use crate::{paths::Paths, spec::Spec}; #[derive(Parser)] #[command(author, version, about, long_about = None)] pub(crate) struct Cli { /// Path to the directory it should operate on. Defaults to the current working directory. #[arg(value_name = "DIR")] pub(crate) path: Option, } pub(crate) fn setup() -> Result<(Paths, Spec)> { let cli = Cli::parse(); let base_dir = cli .path .ok_or_else(|| anyhow!("No path specified in CLI parameters.")) .or_else(|_| std::env::current_dir()) .context( "Couldn't get current dir from env, and no path was specified in CLI parameters either", )?; let paths = Paths::new(base_dir); let spec_string = std::fs::read_to_string(&paths.spec).context("Failed to read spec into string")?; let spec: Spec = serde_yaml::from_str(&spec_string).context("Failed to parse spec from string")?; Ok((paths, spec)) }