73 lines
2.0 KiB
Rust
73 lines
2.0 KiB
Rust
// Workspace: config
|
|
// File: config/src/graph.rs
|
|
//! The inner config for graph module
|
|
//!
|
|
use clap::Args;
|
|
use phf::phf_map;
|
|
use std::sync::LazyLock;
|
|
|
|
#[derive(Args, Debug, Clone)]
|
|
/// The configuration struct for the Graph
|
|
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<String>,
|
|
|
|
/// 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
|
|
static HELP_STR_TO_GRAPH: LazyLock<String> = LazyLock::new(|| {
|
|
let targets = STR_TO_GRAPH_TARGET_TYPE
|
|
.keys()
|
|
.map(|v| v.to_string())
|
|
.collect::<Vec<String>>();
|
|
targets.join(", ").to_string()
|
|
});
|
|
|
|
#[derive(Debug, Clone)]
|
|
/// All target type
|
|
pub enum GraphTargetType {
|
|
/// 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
|
|
)
|
|
}
|
|
}
|
|
}
|