From 725cd9cfc4c1cdf2fbbbcd05d4d7e8405cf45afd Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Sun, 9 Feb 2025 00:01:58 +0100 Subject: [PATCH] Refactor in progress --- Cargo.toml | 4 +- cli_parser/Cargo.toml | 28 ++ cli_parser/src/lib.rs | 118 ++++++ config/Cargo.toml | 25 ++ config/src/lib.rs | 337 ++++++++++++++++++ graphs/Cargo.toml | 26 ++ graphs/src/lib.rs | 14 + make/Cargo.toml | 26 ++ make/src/lib.rs | 14 + ravenous-tools/Cargo.toml | 6 + ravenous-tools/src/graphs.rs | 73 +--- ravenous-tools/src/main.rs | 82 +---- ravenous-tools/src/makepdf.rs | 56 +-- ravenous-tools/src/makepdf_functions.rs | 7 +- ravenous-tools/src/makepdf_misc.rs | 112 ------ ravenous-tools/src/makepdf_structs.rs | 41 +-- ravenous-tools/src/stat_io.rs | 3 +- ravenous-tools/src/stats.rs | 20 +- ravenous-tools/src/table_structs.rs | 146 -------- stats/Cargo.toml | 26 ++ stats/src/lib.rs | 14 + tablegen/Cargo.toml | 11 + tablegen/src/lib.rs | 19 +- tablegen/src/table_structs.rs | 51 +++ .../src/table_types.rs | 2 +- {ravenous-tools => tablegen}/src/tablegen.rs | 8 +- 26 files changed, 739 insertions(+), 530 deletions(-) create mode 100644 cli_parser/Cargo.toml create mode 100644 cli_parser/src/lib.rs create mode 100644 config/Cargo.toml create mode 100644 config/src/lib.rs create mode 100644 graphs/Cargo.toml create mode 100644 graphs/src/lib.rs create mode 100644 make/Cargo.toml create mode 100644 make/src/lib.rs delete mode 100644 ravenous-tools/src/table_structs.rs create mode 100644 stats/Cargo.toml create mode 100644 stats/src/lib.rs create mode 100644 tablegen/src/table_structs.rs rename {ravenous-tools => tablegen}/src/table_types.rs (99%) rename {ravenous-tools => tablegen}/src/tablegen.rs (98%) diff --git a/Cargo.toml b/Cargo.toml index 3b7d8db..b77e6b7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [workspace] -members = [ - "ravenous-tools", +members = [ "cli_parser", "config", "graphs", "make", + "ravenous-tools", "stats", "tablegen", ] resolver = "3" diff --git a/cli_parser/Cargo.toml b/cli_parser/Cargo.toml new file mode 100644 index 0000000..9576d68 --- /dev/null +++ b/cli_parser/Cargo.toml @@ -0,0 +1,28 @@ +[package] +name = "cli_parser" +version = "0.1.0" +edition = "2024" + +[dependencies] +config = {path = "../config"} +anyhow = "1.0.95" +clap = { version = "4.5.28", features = ["derive"] } +serde = { version = "1.0.217", features = ["derive", "alloc"] } + +# charts-rs = { version = "0.3.11" } +# console = "0.15.8" +# csv = "1.3.0" +# debug_print = "1.0.0" +# dynfmt = { version = "0.1.5", features = ["curly"] } +# glob = "0.3.1" +# indexmap = "2.2.6" +# indicatif = "0.17.8" +# logos = "0.14.0" +# phf = { version = "0.11.2", features = ["macros"] } +# regex = "1.10.5" +# regex_static = "0.1.1" +# ron = "0.8.1" +# serde = { version = "1.0.203", features = ["derive"] } +# serde_json = "1.0.117" +# tokio = { version = "1.38.0", features = ["full"] } +# toml = "0.8.14" diff --git a/cli_parser/src/lib.rs b/cli_parser/src/lib.rs new file mode 100644 index 0000000..04fc954 --- /dev/null +++ b/cli_parser/src/lib.rs @@ -0,0 +1,118 @@ +use clap::{Args, Parser, Subcommand}; +use config::HELP_BLOCK_SELECTION; +use config::HELP_BUILD_TARGET_LIST; +use config::HELP_VERBOSITY_LEVEL; +use config::MakeTargets; +use config::VerboseLevel; +use config::{Craft, GraphConfig, StatConfig, TableArgs}; +use serde::Deserialize; + +// use graphs::{GraphConfig, make_graphs}; +// use makepdf::{MakeConfig, make_pdf}; +// use stats::{StatConfig, stat_solver}; +// use table_structs::Craft; + +#[derive(Parser, Debug)] +#[command(version, about)] +#[command(propagate_version = true)] +/// The list of commands to run +pub struct ParserCLIArgs { + /// The subcommand to run. + #[command(subcommand)] + pub command: Commands, +} + +#[derive(Subcommand, Debug)] +/// Enum representing the available commands. +pub enum Commands { + /// Generate a table from input data using the provided arguments. + Tablegen(TableArgs), + /// Show/Export config + Config(ConfigArgs), + /// Handle stat repartition + Stats(StatConfig), + /// Make a pdf via pdflatex + Make(MakeConfig), + /// Make all graphs + Graphs(GraphConfig), +} + +#[derive(Debug, Args)] +pub struct ConfigArgs { + /// Wether to write the config to file, or just show it + #[arg(short, long, default_value_t = false)] + pub write: bool, + + /// Wether to overwrite the file if it exists + #[arg(short, long, default_value_t = false)] + pub force: bool, + + /// The path to overwrite to + pub path: Option, +} + +#[derive(Deserialize)] +/// The config struct, holding all runtime information +pub struct Config { + // TODO: Check this pub BS + /// Config specific for the classes table generation + pub classes: Classes, + /// Config for all the tables + pub craft: Craft, +} + +#[derive(Deserialize)] +/// The classes config +pub struct Classes { + // TODO: Check this pub BS + /// The header string formatter + pub header: String, + /// The row string formatter + pub tier: String, + /// The row string separator + pub sep: String, + /// The table end string formatter + 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()))] + pub target: Option, + + /// The verbosity level + #[arg(short, long, default_value = "warning", help = format!("The verbosity level. [{}]",HELP_VERBOSITY_LEVEL.as_str()))] + pub verbosity: VerboseLevel, + + /// The progress bar style + #[arg(short, long, default_value = "class", help = format!("The progress bar style. [{}]",HELP_BLOCK_SELECTION.as_str()))] + pub pbar: String, + + /// switch to non interactive mode + #[arg(short = 'N', long, default_value_t = false)] + pub non_interactive: bool, + + /// Select only these targets + #[arg(short, long, value_name = "FILE", group = "select")] + pub only: Vec, + + /// Deselect these targets + #[arg(short, long, value_name = "FILE", group = "select")] + pub no: Vec, + + /// Wether to add the initial and final context + #[arg(short = 'C', long, action = clap::ArgAction::SetFalse)] + pub no_context: bool, + + /// Activate shell escape + #[arg(short, long)] + pub shell_escape: bool, +} diff --git a/config/Cargo.toml b/config/Cargo.toml new file mode 100644 index 0000000..138e76e --- /dev/null +++ b/config/Cargo.toml @@ -0,0 +1,25 @@ +[package] +name = "config" +version = "0.1.0" +edition = "2024" + +[dependencies] +anyhow = "1.0.86" +charts-rs = { version = "0.3.11" } +clap = { version = "4.5.7", features = ["derive"] } +console = "0.15.8" +csv = "1.3.0" +debug_print = "1.0.0" +dynfmt = { version = "0.1.5", features = ["curly"] } +glob = "0.3.1" +indexmap = "2.2.6" +indicatif = "0.17.8" +logos = "0.14.0" +phf = { version = "0.11.2", features = ["macros"] } +regex = "1.10.5" +regex_static = "0.1.1" +ron = "0.8.1" +serde = { version = "1.0.203", features = ["derive"] } +serde_json = "1.0.117" +tokio = { version = "1.38.0", features = ["full"] } +toml = "0.8.14" diff --git a/config/src/lib.rs b/config/src/lib.rs new file mode 100644 index 0000000..c118031 --- /dev/null +++ b/config/src/lib.rs @@ -0,0 +1,337 @@ +//! Holds config and traits +//! +//! Also write configs to disk + +//! Holds all the data structures away from the main routine +use clap::Args; +use phf::phf_map; +use serde::Deserialize; +use std::{collections::HashMap, fmt::Debug, sync::LazyLock}; + +// Table generation structs + +/// An enumeration representing different target types. +#[derive(Debug, Clone)] +pub enum TableGenerationTarget { + /// Processes all classes + Classes, + /// Processes all the craft tables + Craft, + /// Processes only the given files + Files, + /// Processes all the known targets + 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 +pub 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 { + /// Wether to export all files (if used), or output everything to stdout + #[arg(short)] + 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, +} + +// This config is can contain unconstructed code for compatibility purposes +#[allow(dead_code)] +#[derive(Deserialize)] +/// The Craft configs +pub struct Craft { + /// The food header string formatter + pub header_food: String, + /// The alchemy header string formatter + pub header_alchemy: String, + /// The forge header string formatter + pub header_forge: String, + /// The mtrap header string formatter + pub header_mtrap: String, + /// The weapons header string formatter + pub header_weapons: String, + /// The armors header string formatter + pub header_armors: String, + /// The gadgets header string formatter + pub header_gadgets: String, + /// The potions header string formatter + pub header_potions: String, + /// The traps header string formatter + pub header_traps: String, + /// The table end string formatter + pub end: String, + /// The long table end string formatter + pub end_long: String, + /// The long sideways table end string formatter + pub end_long_side: String, + /// The no_headers table end string formatter + pub end_empty: String, +} + +// Statsolver Structs + +#[derive(Args, Debug, Clone)] +/// The configuration struct for the StatSolver +pub struct StatConfig { + // #[arg(default_value_t: "data/Book1.csv")] + /// The path where the data to analyse is + pub config_path: String, + /// The verbosity level + #[arg(short, long, default_value_t = false)] + pub verbosity: bool, +} + +// Graphconfig +#[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() {} +// } +// + +// Make + +/// 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 + .keys() + .map(|v| v.to_owned()) + .collect::>(); + targets.sort(); + 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)] +pub enum VerboseLevel { + /// Shouldn't be printed no matter what + None, + /// Garbage + Misc, + /// Boxness, barely above Misc + Box, + /// Context info (Debug info) + Context, + /// Usefull info + Info, + /// Important warnings + Warning, + /// Errors encountered requiring user input + Error, + /// Uncatachable 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(|| { + let mut m = HashMap::new(); + m.insert("class".to_string(), "#>-".to_string()); + m.insert("cargo".to_string(), "#> ".to_string()); + m.insert("rough".to_string(), "█ ".to_string()); + m.insert("fine".to_string(), "█▉▊▋▌▍▎▏ ".to_string()); + m.insert("vert".to_string(), "█▇▆▅▄▃▂▁ ".to_string()); + m.insert("fade".to_string(), "█▓▒░ ".to_string()); + m.insert("block".to_string(), "█▛▌▖ ".to_string()); + m.insert("curse".to_string(), "▓▙▚▐▔ ▛▘▖▄▟▞▂█".to_string()); + m.insert("load".to_string(), " ⱠØ₳Đł₦₲ ".to_string()); + m.insert("cool".to_string(), "▰▱".to_string()); + m.insert("neo".to_string(), "▰═".to_string()); + m +}); +// Spinners +// ▁ ▂ ▃ ▄ ▅ ▆ ▇ █ ▇ ▆ ▅ ▄ ▃ ▁ +// ▉▊▋▌▍▎▏▎▍▌▋▊▉ +// ▖ ▘ ▝ ▗ +// ┤ ┘ ┴ └ ├ ┌ ┬ ┐ +// ◢ ◣ ◤ ◥ +// ◡◡ ⊙⊙ ◠◠ +// ⣾⣽⣻⢿⡿⣟⣯⣷ ⠁⠂⠄⡀⢀⠠⠐⠈ +// .tick_strings(&[ +// "▹▹▹▹▹", +// "▸▹▹▹▹", +// "▹▸▹▹▹", +// "▹▹▸▹▹", +// "▹▹▹▸▹", +// "▹▹▹▹▸", +// "▪▪▪▪▪", +// ]), +// + +/// List of all alternative targets +#[derive(Debug, Clone)] +pub enum MakeTargets { + /// Make all targets + All, + /// Make a list of all optionals + List, + /// Make glossaries + Glossaries, + /// 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/graphs/Cargo.toml b/graphs/Cargo.toml new file mode 100644 index 0000000..02b1cd2 --- /dev/null +++ b/graphs/Cargo.toml @@ -0,0 +1,26 @@ +[package] +name = "graphs" +version = "0.1.0" +edition = "2024" + +[dependencies] +config = {path = "../config"} +anyhow = "1.0.86" +charts-rs = { version = "0.3.11" } +clap = { version = "4.5.7", features = ["derive"] } +console = "0.15.8" +csv = "1.3.0" +debug_print = "1.0.0" +dynfmt = { version = "0.1.5", features = ["curly"] } +glob = "0.3.1" +indexmap = "2.2.6" +indicatif = "0.17.8" +logos = "0.14.0" +phf = { version = "0.11.2", features = ["macros"] } +regex = "1.10.5" +regex_static = "0.1.1" +ron = "0.8.1" +serde = { version = "1.0.203", features = ["derive"] } +serde_json = "1.0.117" +tokio = { version = "1.38.0", features = ["full"] } +toml = "0.8.14" diff --git a/graphs/src/lib.rs b/graphs/src/lib.rs new file mode 100644 index 0000000..b93cf3f --- /dev/null +++ b/graphs/src/lib.rs @@ -0,0 +1,14 @@ +pub fn add(left: u64, right: u64) -> u64 { + left + right +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn it_works() { + let result = add(2, 2); + assert_eq!(result, 4); + } +} diff --git a/make/Cargo.toml b/make/Cargo.toml new file mode 100644 index 0000000..878114e --- /dev/null +++ b/make/Cargo.toml @@ -0,0 +1,26 @@ +[package] +name = "make" +version = "0.1.0" +edition = "2024" + +[dependencies] +config = {path = "../config"} +anyhow = "1.0.86" +charts-rs = { version = "0.3.11" } +clap = { version = "4.5.7", features = ["derive"] } +console = "0.15.8" +csv = "1.3.0" +debug_print = "1.0.0" +dynfmt = { version = "0.1.5", features = ["curly"] } +glob = "0.3.1" +indexmap = "2.2.6" +indicatif = "0.17.8" +logos = "0.14.0" +phf = { version = "0.11.2", features = ["macros"] } +regex = "1.10.5" +regex_static = "0.1.1" +ron = "0.8.1" +serde = { version = "1.0.203", features = ["derive"] } +serde_json = "1.0.117" +tokio = { version = "1.38.0", features = ["full"] } +toml = "0.8.14" diff --git a/make/src/lib.rs b/make/src/lib.rs new file mode 100644 index 0000000..b93cf3f --- /dev/null +++ b/make/src/lib.rs @@ -0,0 +1,14 @@ +pub fn add(left: u64, right: u64) -> u64 { + left + right +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn it_works() { + let result = add(2, 2); + assert_eq!(result, 4); + } +} diff --git a/ravenous-tools/Cargo.toml b/ravenous-tools/Cargo.toml index b1af0e2..7701032 100644 --- a/ravenous-tools/Cargo.toml +++ b/ravenous-tools/Cargo.toml @@ -5,6 +5,12 @@ version = "0.1.4" edition = "2024" [dependencies] +tablegen = {path = "../tablegen"} +graphs = {path = "../graphs"} +make = {path = "../make"} +cli_parser = {path = "../cli_parser"} +config = {path = "../config"} + anyhow = "1.0.86" charts-rs = { version = "0.3.11" } clap = { version = "4.5.7", features = ["derive"] } diff --git a/ravenous-tools/src/graphs.rs b/ravenous-tools/src/graphs.rs index ae69d0f..ceedff1 100644 --- a/ravenous-tools/src/graphs.rs +++ b/ravenous-tools/src/graphs.rs @@ -2,52 +2,15 @@ use charts_rs::{Box, Color}; use charts_rs::{RadarChart, RadarIndicator, Series, get_or_try_init_fonts}; +use cli_parser::Config; +use config::{GraphConfig, GraphTargetType}; use glob::glob; use serde::{Deserialize, Serialize}; use std::io::Read; use std::process::Command; -use std::{f32, fs::File, io::Write, iter, sync::LazyLock}; +use std::{fs::File, io::Write, iter}; use anyhow::{Context, Result}; -use clap::Args; -use phf::phf_map; - -use crate::Config; - -#[derive(Args, Debug, Clone)] -/// The configuration struct for the PdfMaker -pub(super) struct GraphConfig { - /// Special target - #[arg(help = format!("The target to execute [{}]", *HELP_STR_TO_GRAPH))] - target: GraphTargetType, - - /// Alternative origin - #[arg(short, long, default_value = "Images/Radar/radar.csv")] - origin: String, - - /// Alternative destination - #[arg(short, long, default_value = "Images/Radar")] - destination: String, - - /// Alternative config to load (generate a new one with init) - #[arg(short, long)] - config: Option, - - /// Clean all the artefacts (including generated images) - #[arg(short, long)] - all: bool, -} - -#[derive(Debug, Clone)] -/// All target type -pub(super) enum GraphTargetType { - /// Make all graphs - Generate, - /// Clean all graphs - Remove, - /// Initialize the connfig - Init, -} /// Main action dispatch for the graph make pub(super) fn make_graphs(args: &GraphConfig, _config: &Config) -> Result<()> { @@ -233,36 +196,6 @@ fn cleanup_csv(mut rdr: csv::Reader) -> Result { }) } -/// 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(super) 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() -}); - -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 - ) - } - } -} impl MiniTheme { /// The default theme for out tool pub fn new() -> Self { diff --git a/ravenous-tools/src/main.rs b/ravenous-tools/src/main.rs index fb62d80..c9153ac 100644 --- a/ravenous-tools/src/main.rs +++ b/ravenous-tools/src/main.rs @@ -14,84 +14,22 @@ mod stat_algo; mod stat_io; mod stat_structs; mod stats; -mod table_structs; -mod table_types; -mod tablegen; -use crate::table_structs::TableArgs; + +use clap::Parser; +// mod table_structs; +// mod table_types; +// mod tablegen; +use cli_parser::{Commands, Config, ConfigArgs, ParserCLIArgs}; use std::{ fs::{self, OpenOptions}, io::Write, }; - -use anyhow::{Context, Result}; -use clap::{Args, Parser, Subcommand}; -use graphs::{GraphConfig, make_graphs}; -use makepdf::{MakeConfig, make_pdf}; -use serde::Deserialize; -use stats::{StatConfig, stat_solver}; -use table_structs::Craft; use tablegen::table_gen; -#[derive(Parser, Debug)] -#[command(version, about)] -#[command(propagate_version = true)] -/// The list of commands to run -struct ParserCLIArgs { - /// The subcommand to run. - #[command(subcommand)] - command: Commands, -} - -#[derive(Subcommand, Debug)] -/// Enum representing the available commands. -enum Commands { - /// Generate a table from input data using the provided arguments. - Tablegen(TableArgs), - /// Show/Export config - Config(ConfigArgs), - /// Handle stat repartition - Stats(StatConfig), - /// Make a pdf via pdflatex - Make(MakeConfig), - /// Make all graphs - Graphs(GraphConfig), -} - -#[derive(Debug, Args)] -struct ConfigArgs { - /// Wether to write the config to file, or just show it - #[arg(short, long, default_value_t = false)] - write: bool, - - /// Wether to overwrite the file if it exists - #[arg(short, long, default_value_t = false)] - force: bool, - - /// The path to overwrite to - path: Option, -} - -#[derive(Deserialize)] -/// The config struct, holding all runtime information -struct Config { - /// Config specific for the classes table generation - classes: Classes, - /// Config for all the tables - craft: Craft, -} - -#[derive(Deserialize)] -/// The classes config -struct Classes { - /// The header string formatter - header: String, - /// The row string formatter - tier: String, - /// The row string separator - sep: String, - /// The table end string formatter - end: String, -} +use anyhow::{Context, Result}; +use graphs::make_graphs; +use makepdf::make_pdf; +use stats::stat_solver; fn main() -> Result<()> { let args = ParserCLIArgs::parse(); diff --git a/ravenous-tools/src/makepdf.rs b/ravenous-tools/src/makepdf.rs index 3e67393..2e60616 100644 --- a/ravenous-tools/src/makepdf.rs +++ b/ravenous-tools/src/makepdf.rs @@ -4,6 +4,8 @@ use std::time::{Duration, Instant}; // use std::str::pattern::Pattern; use std::fmt::Write; +use cli_parser::MakeConfig; +use config::{BLOCK_PROGRESSION, HELP_BLOCK_SELECTION, MakeTargets, VerboseLevel}; use dynfmt::FormatArgs; use indicatif::{ProgressBar, ProgressState, ProgressStyle}; use logos::Logos; @@ -11,61 +13,17 @@ use std::str; use tokio::io::{AsyncBufReadExt, BufReader}; use tokio::process::Command; -use anyhow::{anyhow, Result}; -use clap::Args; +use anyhow::{Result, anyhow}; use std::process::Stdio; +use crate::Config; use crate::makepdf_functions::{ - make_clean, make_file, make_glossaries, make_list, BuilderParseResult, -}; -use crate::makepdf_misc::{ - BLOCK_PROGRESSION, HELP_BLOCK_SELECTION, HELP_BUILD_TARGET_LIST, HELP_VERBOSITY_LEVEL, + BuilderParseResult, make_clean, make_file, make_glossaries, make_list, }; use crate::makepdf_structs::{ - BuildInfo, LineType, MakeTargets, Status, VerboseLevel, COL_INFO, COL_NORMAL, TXT_BOXX, - TXT_CNTX, TXT_CRIT, TXT_ERRR, TXT_INFO, TXT_MISC, TXT_UKNW, TXT_WARN, + BuildInfo, COL_INFO, COL_NORMAL, LineType, Status, TXT_BOXX, TXT_CNTX, TXT_CRIT, TXT_ERRR, + TXT_INFO, TXT_MISC, TXT_UKNW, TXT_WARN, }; -use crate::Config; - -#[derive(Args, Debug, Clone)] -// #[command(after_)] -/// The configuration struct for the PdfMaker -pub(super) struct MakeConfig { - /// The filename to compile - pub(super) filename: String, - - /// Special target - #[arg(short, long, help = format!("Build with a special target. [{}]", HELP_BUILD_TARGET_LIST.as_str()))] - pub(super) target: Option, - - /// The verbosity level - #[arg(short, long, default_value = "warning", help = format!("The verbosity level. [{}]",HELP_VERBOSITY_LEVEL.as_str()))] - pub(super) verbosity: VerboseLevel, - - /// The progress bar style - #[arg(short, long, default_value = "class", help = format!("The progress bar style. [{}]",HELP_BLOCK_SELECTION.as_str()))] - pub(super) pbar: String, - - /// switch to non interactive mode - #[arg(short = 'N', long, default_value_t = false)] - pub(super) non_interactive: bool, - - /// Select only these targets - #[arg(short, long, value_name = "FILE", group = "select")] - pub(super) only: Vec, - - /// Deselect these targets - #[arg(short, long, value_name = "FILE", group = "select")] - pub(super) no: Vec, - - /// Wether to add the initial and final context - #[arg(short = 'C', long, action = clap::ArgAction::SetFalse)] - pub(super) no_context: bool, - - /// Activate shell escape - #[arg(short, long)] - pub(super) shell_escape: bool, -} /// Make a pdf spawning a subprocess pub(super) fn make_pdf(args: &MakeConfig, _config: &Config) -> Result<()> { diff --git a/ravenous-tools/src/makepdf_functions.rs b/ravenous-tools/src/makepdf_functions.rs index 7d152a6..c950337 100644 --- a/ravenous-tools/src/makepdf_functions.rs +++ b/ravenous-tools/src/makepdf_functions.rs @@ -1,5 +1,4 @@ //! Helper functions - use std::{ fs::File, io::{Read, Write}, @@ -10,13 +9,11 @@ use std::{ }; use anyhow::Result; +use cli_parser::MakeConfig; use indexmap::IndexMap; use regex::Regex; -use crate::{ - makepdf::MakeConfig, - makepdf_structs::{COL_ERROR, COL_INFO, COL_MISC, COL_WARNING}, -}; +use crate::makepdf_structs::{COL_ERROR, COL_INFO, COL_MISC, COL_WARNING}; /// Regex detecting wether an input line is present static INPUT_REGEX: LazyLock = diff --git a/ravenous-tools/src/makepdf_misc.rs b/ravenous-tools/src/makepdf_misc.rs index 83bcf5f..161cd38 100644 --- a/ravenous-tools/src/makepdf_misc.rs +++ b/ravenous-tools/src/makepdf_misc.rs @@ -1,113 +1 @@ //! Printing and misc utilities - -use crate::makepdf_structs::{MakeTargets, VerboseLevel}; -use phf::phf_map; -use std::{collections::HashMap, 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(super) static HELP_BLOCK_SELECTION: LazyLock = LazyLock::new(|| { - let mut targets = BLOCK_PROGRESSION - .keys() - .map(|v| v.to_owned()) - .collect::>(); - targets.sort(); - targets.join(", ").to_string() -}); - -/// List all targets -pub(super) 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(super) 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() -}); - -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 - ) - } - } -} - -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 - ) - } - } -} - -/// All progress bar styles -pub(super) static BLOCK_PROGRESSION: LazyLock> = LazyLock::new(|| { - let mut m = HashMap::new(); - m.insert("class".to_string(), "#>-".to_string()); - m.insert("cargo".to_string(), "#> ".to_string()); - m.insert("rough".to_string(), "█ ".to_string()); - m.insert("fine".to_string(), "█▉▊▋▌▍▎▏ ".to_string()); - m.insert("vert".to_string(), "█▇▆▅▄▃▂▁ ".to_string()); - m.insert("fade".to_string(), "█▓▒░ ".to_string()); - m.insert("block".to_string(), "█▛▌▖ ".to_string()); - m.insert("curse".to_string(), "▓▙▚▐▔ ▛▘▖▄▟▞▂█".to_string()); - m.insert("load".to_string(), " ⱠØ₳Đł₦₲ ".to_string()); - m.insert("cool".to_string(), "▰▱".to_string()); - m.insert("neo".to_string(), "▰═".to_string()); - m -}); -// Spinners -// ▁ ▂ ▃ ▄ ▅ ▆ ▇ █ ▇ ▆ ▅ ▄ ▃ ▁ -// ▉▊▋▌▍▎▏▎▍▌▋▊▉ -// ▖ ▘ ▝ ▗ -// ┤ ┘ ┴ └ ├ ┌ ┬ ┐ -// ◢ ◣ ◤ ◥ -// ◡◡ ⊙⊙ ◠◠ -// ⣾⣽⣻⢿⡿⣟⣯⣷ ⠁⠂⠄⡀⢀⠠⠐⠈ -// .tick_strings(&[ -// "▹▹▹▹▹", -// "▸▹▹▹▹", -// "▹▸▹▹▹", -// "▹▹▸▹▹", -// "▹▹▹▸▹", -// "▹▹▹▹▸", -// "▪▪▪▪▪", -// ]), diff --git a/ravenous-tools/src/makepdf_structs.rs b/ravenous-tools/src/makepdf_structs.rs index 3d33b11..507fbde 100644 --- a/ravenous-tools/src/makepdf_structs.rs +++ b/ravenous-tools/src/makepdf_structs.rs @@ -1,5 +1,6 @@ //! Holds all the structs for the makepdf module - +use cli_parser::MakeConfig; +use config::VerboseLevel; use logos::Logos; use serde::{Deserialize, Serialize}; use std::{ @@ -10,7 +11,7 @@ use std::{ use console::Style; -use crate::{makepdf::MakeConfig, makepdf_functions::BuilderParseResult}; +use crate::makepdf_functions::BuilderParseResult; /// Color Scheme for the NORMAL level pub(super) static COL_NORMAL: LazyLock