From 3460841ed75ded0912d0d635f418dc011225a142 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 | 4 +- crates/cli_parser/src/lib.rs | 10 ++-- crates/config/Cargo.toml | 1 - crates/config/src/graph.rs | 6 +-- crates/config/src/make.rs | 89 ++--------------------------------- crates/config/src/tablegen.rs | 38 +-------------- crates/tablegen/Cargo.toml | 4 +- 7 files changed, 18 insertions(+), 134 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ba2561f..f0375c4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -57,7 +57,6 @@ tokio = { version = "1.52.3", features = ["full"] } 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"] } @@ -67,4 +66,7 @@ glob = "0.3.3" tokio = "1.49.0" >>>>>>> 6becdfb (Updates dependencies) dynfmt = { version = "0.1.5", features = ["curly"] } +<<<<<<< HEAD pretty_assertions = "^1.4" +======= +>>>>>>> 6a1e9d3 (Removed nearly all phf references) diff --git a/crates/cli_parser/src/lib.rs b/crates/cli_parser/src/lib.rs index 5529c86..1fd3ad2 100644 --- a/crates/cli_parser/src/lib.rs +++ b/crates/cli_parser/src/lib.rs @@ -8,10 +8,7 @@ use config::{ fast_tables::FastTableConfig, formatter::FormatterConfig, graph::GraphConfig, - make::{ - HELP_BLOCK_SELECTION, HELP_BUILD_TARGET_LIST, HELP_VERBOSITY_LEVEL, MakeTargets, - VerboseLevel, - }, + make::{MakeTargets, VerboseLevel, HELP_BLOCK_SELECTION}, statsolver::StatConfig, tablegen::{Craft, TableArgs}, }; @@ -102,18 +99,17 @@ pub struct Datagen { // 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 1fc9b4a..efe5486 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 39c1224..d3bccd7 100644 --- a/crates/config/src/graph.rs +++ b/crates/config/src/graph.rs @@ -2,7 +2,7 @@ // File: config/src/graph.rs //! The inner config for graph module //! -use clap::Args; +use clap::{Args, ValueEnum}; use phf::phf_map; use serde::{Deserialize, Serialize}; use std::{ops::Add, sync::LazyLock}; @@ -11,7 +11,6 @@ use std::{ops::Add, sync::LazyLock}; /// 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 @@ -50,7 +49,7 @@ static HELP_STR_TO_GRAPH: LazyLock = LazyLock::new(|| { targets.join(", ").to_string() }); -#[derive(Debug, Clone)] +#[derive(ValueEnum, Debug, Clone)] /// All target type pub enum GraphTargetType { /// Load graph data from the classes @@ -62,6 +61,7 @@ pub enum GraphTargetType { /// Initialize the connfig Init, } +<<<<<<< HEAD impl From<&str> for GraphTargetType { fn from(value: &str) -> Self { if let Some(target) = STR_TO_GRAPH_TARGET_TYPE.get(&value.to_lowercase()).cloned() { 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 ced1cac..49a0329 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"] } +