From 6a1e9d323f987061c158949367f8e1697c18d4e0 Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Fri, 23 Jan 2026 12:16:34 +0100 Subject: [PATCH] Removed nearly all phf references --- Cargo.toml | 3 -- crates/cli_parser/src/lib.rs | 12 ++--- crates/config/Cargo.toml | 1 - crates/config/src/graph.rs | 37 +-------------- crates/config/src/make.rs | 89 ++--------------------------------- crates/config/src/tablegen.rs | 38 +-------------- crates/tablegen/Cargo.toml | 4 +- 7 files changed, 14 insertions(+), 170 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 28c2069..5ac915a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,7 +38,6 @@ fast_class = {path = "./crates/fast_class"} anyhow = "1.0.100" toml = "0.9.11" clap = { version = "4.5.54", features = ["derive"] } -phf = { version = "0.13.1", features = ["macros"] } regex = "1.12.2" regex_static = "0.1.1" serde = { version = "1.0.228", features = ["derive", "alloc"] } @@ -47,5 +46,3 @@ ron = "0.12.0" glob = "0.3.3" tokio = "1.49.0" dynfmt = { version = "0.1.5", features = ["curly"] } - - diff --git a/crates/cli_parser/src/lib.rs b/crates/cli_parser/src/lib.rs index 832c9c4..f60f5d2 100644 --- a/crates/cli_parser/src/lib.rs +++ b/crates/cli_parser/src/lib.rs @@ -6,10 +6,7 @@ use clap::{Args, Parser, Subcommand}; use config::{ fast_tables::FastTableConfig, graph::GraphConfig, - make::{ - HELP_BLOCK_SELECTION, HELP_BUILD_TARGET_LIST, HELP_VERBOSITY_LEVEL, MakeTargets, - VerboseLevel, - }, + make::{HELP_BLOCK_SELECTION, MakeTargets, VerboseLevel}, statsolver::StatConfig, tablegen::{Craft, TableArgs}, }; @@ -84,21 +81,18 @@ pub struct Classes { pub end: String, } -// The make structs - #[derive(Args, Debug, Clone)] -// #[command(after_)] /// The configuration struct for the PdfMaker pub struct MakeConfig { /// The filename to compile pub filename: String, /// Special target - #[arg(short, long, help = format!("Build with a special target. [{}]", HELP_BUILD_TARGET_LIST.as_str()))] + #[arg(short, long)] pub target: Option, /// The verbosity level - #[arg(short, long, default_value = "warning", help = format!("The verbosity level. [{}]",HELP_VERBOSITY_LEVEL.as_str()))] + #[arg(short, long, default_value = "warning")] pub verbosity: VerboseLevel, /// The progress bar style diff --git a/crates/config/Cargo.toml b/crates/config/Cargo.toml index eb81d9a..67987ea 100644 --- a/crates/config/Cargo.toml +++ b/crates/config/Cargo.toml @@ -5,5 +5,4 @@ edition = "2024" [dependencies] clap = {workspace = true} -phf = {workspace = true} serde = {workspace = true} diff --git a/crates/config/src/graph.rs b/crates/config/src/graph.rs index e57cde7..37371be 100644 --- a/crates/config/src/graph.rs +++ b/crates/config/src/graph.rs @@ -2,15 +2,12 @@ // File: config/src/graph.rs //! The inner config for graph module //! -use clap::Args; -use phf::phf_map; -use std::sync::LazyLock; +use clap::{Args, ValueEnum}; #[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 @@ -30,25 +27,7 @@ pub struct GraphConfig { 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 = LazyLock::new(|| { - let targets = STR_TO_GRAPH_TARGET_TYPE - .keys() - .map(|v| v.to_string()) - .collect::>(); - targets.join(", ").to_string() -}); - -#[derive(Debug, Clone)] +#[derive(ValueEnum, Debug, Clone)] /// All target type pub enum GraphTargetType { /// Make all graphs @@ -58,15 +37,3 @@ pub enum GraphTargetType { /// 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 - ) - } - } -} diff --git a/crates/config/src/make.rs b/crates/config/src/make.rs index 4a777de..2c81156 100644 --- a/crates/config/src/make.rs +++ b/crates/config/src/make.rs @@ -2,28 +2,9 @@ // File: config/src/make.rs //! Makepdf generation structs -use phf::phf_map; +use clap::ValueEnum; use std::{collections::HashMap, fmt::Debug, sync::LazyLock}; -/// Convert str to verbosity level -static STR_TO_VERBOSITY: phf::Map<&'static str, VerboseLevel> = phf_map! { - "misc" =>VerboseLevel::Misc, - "box" => VerboseLevel::Box, - "context" => VerboseLevel::Context, - "info" => VerboseLevel::Info, - "warning" => VerboseLevel::Warning, - "error" => VerboseLevel::Error, - "critical" => VerboseLevel::Critical, -}; - -/// Convert str to build target -static STR_TO_BUILD_TARGET: phf::Map<&'static str, MakeTargets> = phf_map! { - "all" => MakeTargets::All, - "list" => MakeTargets::List, - "glossaries" => MakeTargets::Glossaries, - "clean" => MakeTargets::Clean, -}; - /// List all blocktype pub static HELP_BLOCK_SELECTION: LazyLock = LazyLock::new(|| { let mut targets = BLOCK_PROGRESSION @@ -34,27 +15,8 @@ pub static HELP_BLOCK_SELECTION: LazyLock = LazyLock::new(|| { targets.join(", ").to_string() }); -/// List all targets -pub static HELP_VERBOSITY_LEVEL: LazyLock = LazyLock::new(|| { - let mut targets = STR_TO_VERBOSITY - .values() - .map(|v| format!("{:?}", v).to_lowercase()) - .collect::>(); - targets.sort(); - targets.join(", ").to_string() -}); - -/// List all targets -pub static HELP_BUILD_TARGET_LIST: LazyLock = LazyLock::new(|| { - let targets = STR_TO_BUILD_TARGET - .values() - .map(|v| format!("{:?}", v).to_lowercase()) - .collect::>(); - targets.join(", ").to_string() -}); - /// The verbosity level -#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] +#[derive(ValueEnum, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] pub enum VerboseLevel { /// Shouldn't be printed no matter what None, @@ -70,23 +32,11 @@ pub enum VerboseLevel { Warning, /// Errors encountered requiring user input Error, - /// Uncatachable errors + /// Uncatchable errors Critical, /// Literrally uncatchable things Uncatchable, } -impl From<&str> for VerboseLevel { - fn from(value: &str) -> Self { - if let Some(target) = STR_TO_VERBOSITY.get(&value.to_lowercase()).cloned() { - target - } else { - panic!( - "Invalid debug level {}. The debug level available are (from highest verbosity to lowest): [{:?}]", - value, HELP_VERBOSITY_LEVEL - ) - } - } -} /// All progress bar styles pub static BLOCK_PROGRESSION: LazyLock> = LazyLock::new(|| { @@ -104,27 +54,9 @@ pub static BLOCK_PROGRESSION: LazyLock> = LazyLock::new( m.insert("neo".to_string(), "▰═".to_string()); m }); -// Spinners -// ▁ ▂ ▃ ▄ ▅ ▆ ▇ █ ▇ ▆ ▅ ▄ ▃ ▁ -// ▉▊▋▌▍▎▏▎▍▌▋▊▉ -// ▖ ▘ ▝ ▗ -// ┤ ┘ ┴ └ ├ ┌ ┬ ┐ -// ◢ ◣ ◤ ◥ -// ◡◡ ⊙⊙ ◠◠ -// ⣾⣽⣻⢿⡿⣟⣯⣷ ⠁⠂⠄⡀⢀⠠⠐⠈ -// .tick_strings(&[ -// "▹▹▹▹▹", -// "▸▹▹▹▹", -// "▹▸▹▹▹", -// "▹▹▸▹▹", -// "▹▹▹▸▹", -// "▹▹▹▹▸", -// "▪▪▪▪▪", -// ]), -// /// List of all alternative targets -#[derive(Debug, Clone)] +#[derive(ValueEnum, Debug, Clone)] pub enum MakeTargets { /// Make all targets All, @@ -135,16 +67,3 @@ pub enum MakeTargets { /// Make the working directory clean Clean, } - -impl From<&str> for MakeTargets { - fn from(value: &str) -> Self { - if let Some(target) = STR_TO_BUILD_TARGET.get(&value.to_lowercase()).cloned() { - target - } else { - panic!( - "Invalid build target {}. The build target available are [{:?}]", - value, HELP_BUILD_TARGET_LIST - ) - } - } -} diff --git a/crates/config/src/tablegen.rs b/crates/config/src/tablegen.rs index 82e4b88..7b54be3 100644 --- a/crates/config/src/tablegen.rs +++ b/crates/config/src/tablegen.rs @@ -2,13 +2,11 @@ // File: config/src/tablegen.rs //! Table generation structs -use clap::Args; -use phf::phf_map; +use clap::{Args, ValueEnum}; use serde::Deserialize; -use std::sync::LazyLock; /// An enumeration representing different target types. -#[derive(Debug, Clone)] +#[derive(ValueEnum, Debug, Clone)] pub enum TableGenerationTarget { /// Processes all classes Classes, @@ -20,36 +18,6 @@ pub enum TableGenerationTarget { All, } -impl From<&str> for TableGenerationTarget { - fn from(value: &str) -> Self { - if let Some(target) = STR_TO_TARGET.get(value).cloned() { - target - } else { - panic!( - "Only the following target can be used: {}", - *HELP_STR_TO_TARGET_TABLES - ) - } - } -} - -/// A mapping of string representations to target types. -static STR_TO_TARGET: phf::Map<&'static str, TableGenerationTarget> = phf_map! { - "classes" => TableGenerationTarget::Classes, - "craft" => TableGenerationTarget::Craft, - "files" => TableGenerationTarget::Files, - "all" => TableGenerationTarget::All, -}; - -/// A help of all the table targets to be built -static HELP_STR_TO_TARGET_TABLES: LazyLock = LazyLock::new(|| { - let mut targets = STR_TO_TARGET - .keys() - .map(|v| v.to_string()) - .collect::>(); - targets.sort(); - targets.join(", ").to_string() -}); /// Configuration options for processing TSV files and generating LaTeX tables. #[derive(Debug, Args)] pub struct TableArgs { @@ -58,8 +26,6 @@ pub struct TableArgs { pub export: bool, /// The kind of tables to operate on: classes, craft or files followed by a list of files - // #[arg(help = format!("The kind of tables to operate on : {}", "TODO: FIX"))] - #[arg(help = format!("The kind of tables to operate on : {}", *HELP_STR_TO_TARGET_TABLES))] pub kind: TableGenerationTarget, /// A vector of strings representing the names of TSV files to process. pub filenames: Vec, diff --git a/crates/tablegen/Cargo.toml b/crates/tablegen/Cargo.toml index 3f5d5f3..bc1b1a7 100644 --- a/crates/tablegen/Cargo.toml +++ b/crates/tablegen/Cargo.toml @@ -10,7 +10,9 @@ anyhow = {workspace = true} csv = {workspace = true} dynfmt = {workspace = true} glob = {workspace = true} -phf = {workspace = true} regex = {workspace = true} regex_static = {workspace = true} serde = {workspace = true} +clap = {workspace = true} +phf = { version = "0.13.1", features = ["macros"] } +