From c4a6c5095193567295fbe43a02795a8fa7a46155 Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Fri, 3 May 2024 15:37:27 +0200 Subject: [PATCH] Adds doc --- Cargo.toml | 1 + src/tablegen.rs | 36 ++++++++++++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 53eef8f..9622919 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ edition = "2021" [dependencies] clap = { version = "4.5.4", features = ["derive"] } csv = "1.3.0" +phf = { version = "0.11.2", features = ["macros"] } regex = "1.10.4" serde = { version = "1.0.198", features = ["derive"] } diff --git a/src/tablegen.rs b/src/tablegen.rs index b5a381b..746a709 100644 --- a/src/tablegen.rs +++ b/src/tablegen.rs @@ -1,5 +1,6 @@ //! The csv table generation use clap::Args; +use phf::phf_map; use serde::Deserialize; use std::io::{Error, Write}; use std::path::Path; @@ -13,12 +14,43 @@ pub struct TableArgs { #[arg(short)] export: bool, - // #[arg(shorl, long)] - // type: + /// The kind of tables to operate on: classes, craft or a specific file + kind: TargetType, /// A vector of strings representing the names of CSV files to process. filenames: Vec, } +/// An enumeration representing different target types. +#[derive(Debug, Clone)] +enum TargetType { + /// Processes all classes + Classes, + /// Processes all the craft tables + Craft, + /// Processes only the given files + Files, +} + +/// A mapping of string representations to target types. +static STR_TO_TARGET: phf::Map<&'static str, TargetType> = phf_map! { + "classes" => TargetType::Classes, + "craft" => TargetType::Craft, + "files" => TargetType::Files, +}; + +impl From<&str> for TargetType { + 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: {:?}", + STR_TO_TARGET.keys() + ) + } + } +} + #[derive(Debug, Deserialize)] #[serde(rename_all = "PascalCase")] /// A single row in a martial class csv file