// Workspace: config // File: config/src/graph.rs // Graphconfig use clap::Args; use phf::phf_map; use std::sync::LazyLock; #[derive(Args, Debug, Clone)] /// The configuration struct for the PdfMaker pub struct GraphConfig { /// Special target #[arg(help = format!("The target to execute [{}]", *HELP_STR_TO_GRAPH))] pub target: GraphTargetType, /// Alternative origin #[arg(short, long, default_value = "Images/Radar/radar.csv")] pub origin: String, /// Alternative destination #[arg(short, long, default_value = "Images/Radar")] pub destination: String, /// Alternative config to load (generate a new one with init) #[arg(short, long)] pub config: Option, /// Clean all the artefacts (including generated images) #[arg(short, long)] pub all: bool, } /// Link from user str input to the action to perform static STR_TO_GRAPH_TARGET_TYPE: phf::Map<&'static str, GraphTargetType> = phf_map! { "generate" => GraphTargetType::Generate, "gen" => GraphTargetType::Generate, "remove" => GraphTargetType::Remove, "clean" => GraphTargetType::Remove, "init" => GraphTargetType::Init, }; /// Help listing all the actions availables pub static HELP_STR_TO_GRAPH: LazyLock = LazyLock::new(|| { let targets = STR_TO_GRAPH_TARGET_TYPE .keys() .map(|v| v.to_string()) .collect::>(); targets.join(", ").to_string() }); #[derive(Debug, Clone)] /// All target type pub enum GraphTargetType { // TODO: Check this pub BS /// Make all graphs Generate, /// Clean all graphs Remove, /// Initialize the connfig Init, } impl From<&str> for GraphTargetType { fn from(value: &str) -> Self { if let Some(target) = STR_TO_GRAPH_TARGET_TYPE.get(&value.to_lowercase()).cloned() { target } else { panic!( "Invalid target {}. The target available are : [{}]", value, *HELP_STR_TO_GRAPH ) } } } // #[cfg(test)] // mod tests { // use super::*; // #[test] // fn it_works() {} // } //