diff --git a/Cargo.toml b/Cargo.toml index 73a76e9..0ecab7b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,32 +1,14 @@ -# cargo-features = ["codegen-backend"] -[package] -name = "ravenous-tools" -version = "0.1.4" -edition = "2021" +# cargo-features = ["edition2024"] + +[workspace] +members = [ "cli_parser", "config", "graphs", "make", + "ravenous-tools", "stats", + "tablegen", +] +resolver = "3" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html -[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" - [profile.dev] debug = 0 # codegen-backend = "cranelift" diff --git a/Todo.md b/Todo.md index c9808a5..7f60f7c 100644 --- a/Todo.md +++ b/Todo.md @@ -1,29 +1,50 @@ # Current Tools ## TableGen +# Workspaces + [~] Table + [~] Cleanup + [~] Config + [~] Cleanup + [x] Doc + [~] Stats + [~] Cleanup + [~] Make + [~] Cleanup + [ ] Graphs + [~] Cleanup + [ ] Cli Parser + [ ] Refactor + [ ] Cleanup + [ ] Doc + # Todo -* Auto path (by default) -* Document +[ ] Auto path (by default) +[ ] Document +[ ] Remove most of the unneeded pub +[ ] Update the dependencies +[ ] Remove unneded dependencies +[ ] Switch from anyhow to thiserror ## Tablegen -* Dissociate path from feature -* Force replace/ask -* Have interactive mode ? -* Dissociate Model from generation +[ ] Dissociate path from feature +[ ] Force replace/ask +[ ] Have interactive mode ? +[ ] Dissociate Model from generation ## StatGen -* Get rid of cycle and have a struct that gives stats according to % and keeps tracks of % -* Test VecDeque -* Add testing -* Add the swap algo (swap a bad fit creature with another) -* Save/load states +[ ] Get rid of cycle and have a struct that gives stats according to % and keeps tracks of % +[ ] Test VecDeque +[ ] Add testing +[ ] Add the swap algo (swap a bad fit creature with another) +[ ] Save/load states ## Test Units # Futures tools -* Lexer/Checker +[ ] Lexer/Checker ## Lexer ` Command: grammar --check ` diff --git a/cli_parser/Cargo.toml b/cli_parser/Cargo.toml new file mode 100644 index 0000000..234e5b6 --- /dev/null +++ b/cli_parser/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "cli_parser" +version = "0.1.0" +edition = "2024" + +[dependencies] +config = {path = "../config"} +clap = { version = "4.5.28", features = ["derive"] } +serde = { version = "1.0.217", features = ["derive", "alloc"] } diff --git a/cli_parser/src/lib.rs b/cli_parser/src/lib.rs new file mode 100644 index 0000000..4b543fa --- /dev/null +++ b/cli_parser/src/lib.rs @@ -0,0 +1,123 @@ +//! The usual cli parser shenenigans +//! +use clap::{Args, Parser, Subcommand}; +use config::{ + graph::GraphConfig, + make::{ + HELP_BLOCK_SELECTION, HELP_BUILD_TARGET_LIST, HELP_VERBOSITY_LEVEL, MakeTargets, + VerboseLevel, + }, + statsolver::StatConfig, + tablegen::{Craft, 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..5448a80 --- /dev/null +++ b/config/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "config" +version = "0.1.0" +edition = "2024" + +[dependencies] +clap = { version = "4.5.28", features = ["derive"] } +phf = { version = "0.11.3", features = ["macros"] } +serde = { version = "1.0.217", features = ["derive"] } diff --git a/config/src/graph.rs b/config/src/graph.rs new file mode 100644 index 0000000..a2a7954 --- /dev/null +++ b/config/src/graph.rs @@ -0,0 +1,81 @@ +// Workspace: config +// File: config/src/graph.rs +// Graphconfig +use clap::Args; +use phf::phf_map; +use std::sync::LazyLock; + +#[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() {} +// } +// diff --git a/config/src/lib.rs b/config/src/lib.rs new file mode 100644 index 0000000..920904a --- /dev/null +++ b/config/src/lib.rs @@ -0,0 +1,11 @@ +// Workspace: config +// File: config/src/lib.rs +//! Holds config and traits +//! +//! Also write configs to disk + +// Internal Modules +pub mod graph; +pub mod make; +pub mod statsolver; +pub mod tablegen; diff --git a/src/makepdf_misc.rs b/config/src/make.rs similarity index 73% rename from src/makepdf_misc.rs rename to config/src/make.rs index 83bcf5f..b0f7c67 100644 --- a/src/makepdf_misc.rs +++ b/config/src/make.rs @@ -1,8 +1,9 @@ -//! Printing and misc utilities +// Workspace: config +// File: config/src/make.rs +// Makepdf generation structs -use crate::makepdf_structs::{MakeTargets, VerboseLevel}; use phf::phf_map; -use std::{collections::HashMap, sync::LazyLock}; +use std::{collections::HashMap, fmt::Debug, sync::LazyLock}; /// Convert str to verbosity level static STR_TO_VERBOSITY: phf::Map<&'static str, VerboseLevel> = phf_map! { @@ -24,7 +25,7 @@ static STR_TO_BUILD_TARGET: phf::Map<&'static str, MakeTargets> = phf_map! { }; /// List all blocktype -pub(super) static HELP_BLOCK_SELECTION: LazyLock = LazyLock::new(|| { +pub static HELP_BLOCK_SELECTION: LazyLock = LazyLock::new(|| { let mut targets = BLOCK_PROGRESSION .keys() .map(|v| v.to_owned()) @@ -34,7 +35,7 @@ pub(super) static HELP_BLOCK_SELECTION: LazyLock = LazyLock::new(|| { }); /// List all targets -pub(super) static HELP_VERBOSITY_LEVEL: LazyLock = LazyLock::new(|| { +pub static HELP_VERBOSITY_LEVEL: LazyLock = LazyLock::new(|| { let mut targets = STR_TO_VERBOSITY .values() .map(|v| format!("{:?}", v).to_lowercase()) @@ -44,7 +45,7 @@ pub(super) static HELP_VERBOSITY_LEVEL: LazyLock = LazyLock::new(|| { }); /// List all targets -pub(super) static HELP_BUILD_TARGET_LIST: LazyLock = LazyLock::new(|| { +pub static HELP_BUILD_TARGET_LIST: LazyLock = LazyLock::new(|| { let targets = STR_TO_BUILD_TARGET .values() .map(|v| format!("{:?}", v).to_lowercase()) @@ -52,6 +53,28 @@ pub(super) static HELP_BUILD_TARGET_LIST: LazyLock = LazyLock::new(|| { 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() { @@ -65,21 +88,8 @@ impl From<&str> for VerboseLevel { } } -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(|| { +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()); @@ -111,3 +121,30 @@ pub(super) static BLOCK_PROGRESSION: LazyLock> = LazyLoc // "▹▹▹▹▸", // "▪▪▪▪▪", // ]), +// + +/// 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/config/src/statsolver.rs b/config/src/statsolver.rs new file mode 100644 index 0000000..25905c5 --- /dev/null +++ b/config/src/statsolver.rs @@ -0,0 +1,16 @@ +// Workspace: config +// File: config/src/statsolver.rs +//! Statsolver Structs + +use clap::Args; + +#[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, +} diff --git a/src/table_structs.rs b/config/src/tablegen.rs similarity index 53% rename from src/table_structs.rs rename to config/src/tablegen.rs index be8f819..4b923de 100644 --- a/src/table_structs.rs +++ b/config/src/tablegen.rs @@ -1,58 +1,11 @@ -//! Holds all the data structures away from the main routine +// Workspace: config +// File: config/src/tablegen.rs +//! Table generation structs + use clap::Args; use phf::phf_map; -use regex::Regex; use serde::Deserialize; -use std::{fmt::Debug, sync::LazyLock}; - -use regex_static::once_cell::sync::Lazy; - -// This config is can contain unconstructed code for compatibility purposes -#[allow(dead_code)] -#[derive(Deserialize)] -/// The Craft configs -pub(super) struct Craft { - /// The food header string formatter - pub(super) header_food: String, - /// The alchemy header string formatter - pub(super) header_alchemy: String, - /// The forge header string formatter - pub(super) header_forge: String, - /// The mtrap header string formatter - pub(super) header_mtrap: String, - /// The weapons header string formatter - pub(super) header_weapons: String, - /// The armors header string formatter - pub(super) header_armors: String, - /// The gadgets header string formatter - pub(super) header_gadgets: String, - /// The potions header string formatter - pub(super) header_potions: String, - /// The traps header string formatter - pub(super) header_traps: String, - /// The table end string formatter - pub(super) end: String, - /// The long table end string formatter - pub(super) end_long: String, - /// The long sideways table end string formatter - pub(super) end_long_side: String, - /// The no_headers table end string formatter - pub(super) end_empty: String, -} - -/// Configuration options for processing TSV files and generating LaTeX tables. -#[derive(Debug, Args)] -pub(super) 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 : {}", *HELP_STR_TO_TARGET_TABLES))] - pub kind: TableGenerationTarget, - /// A vector of strings representing the names of TSV files to process. - pub filenames: Vec, -} +use std::sync::LazyLock; /// An enumeration representing different target types. #[derive(Debug, Clone)] @@ -67,71 +20,6 @@ pub enum TableGenerationTarget { All, } -/// 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(super) 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() -}); - -/// All the type of tsv that can be processed by the program -// #[enum_dispatch] -#[derive(Clone)] -pub enum TableTargets { - /// A class tsv - Classes, - /// Foods tsv - Food, - /// Alchemy tsv - Alchemy, - /// Forge tsv - Forge, - /// MPieges tsv - MPieges, - /// Weapons tsv - Weapons, - /// Armors tsv - Armors, - /// Gadgets tsv - Gadgets, - /// Potions tsv - Potions, - /// Traps tsv - Traps, -} - -/// A mapping of string names to target types. -pub(super) static STR_TO_TARGET_FULL: phf::Map<&'static str, TableTargets> = phf_map! { - "cls" => TableTargets::Classes, - "fud" => TableTargets::Food, - "alc" => TableTargets::Alchemy, - "frg" => TableTargets::Forge, - "mpi" => TableTargets::MPieges, - "wpn" => TableTargets::Weapons, - "arm" => TableTargets::Armors, - "gdg" => TableTargets::Gadgets, - "pot" => TableTargets::Potions, - "trp" => TableTargets::Traps, -}; - -/// The regex for finding and replacing all stars with a custom DD -pub(super) static RE_STARS: Lazy = regex_static::lazy_regex!(r"★+"); -/// The regex for finding and replacing all +/- stars with a custom DD -pub(super) static RE_PLUS_STARS: Lazy = regex_static::lazy_regex!(r"([\+-])(★+)"); -/// The regex for finding all (+/-) and replacing them with mathmode -pub(super) static RE_MATHS: Lazy = regex_static::lazy_regex!(r"\([\+-]+\)"); - impl From<&str> for TableGenerationTarget { fn from(value: &str) -> Self { if let Some(target) = STR_TO_TARGET.get(value).cloned() { @@ -144,3 +32,68 @@ impl From<&str> for TableGenerationTarget { } } } + +/// 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, +} diff --git a/graphs/Cargo.toml b/graphs/Cargo.toml new file mode 100644 index 0000000..2b24339 --- /dev/null +++ b/graphs/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "graphs" +version = "0.1.0" +edition = "2024" + +[dependencies] +config = {path = "../config"} +cli_parser = {path = "../cli_parser"} +anyhow = "1.0.95" +charts-rs = "0.3.19" +glob = "0.3.2" +serde = { version = "1.0.217", features = ["derive", "alloc"] } +csv = "1.3.1" +ron = "0.8.1" diff --git a/src/graphs.rs b/graphs/src/graphs.rs similarity index 79% rename from src/graphs.rs rename to graphs/src/graphs.rs index 30822a6..e59212c 100644 --- a/src/graphs.rs +++ b/graphs/src/graphs.rs @@ -1,56 +1,25 @@ -//! Export graphs +//! The module `graphs` is responsible for exporting graphs based on CSV data +//! +//! # Usage +//! +//! - [`make_graphs`]: The main action dispatcher for graph generation and removal. -use charts_rs::{get_or_try_init_fonts, RadarChart, RadarIndicator, Series}; -use charts_rs::{Box, Color}; +use charts_rs::{Box, Color, RadarChart, RadarIndicator, Series, get_or_try_init_fonts}; +use cli_parser::Config; +use config::graph::{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::{Read, Write}, + iter, + process::Command, +}; 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<()> { +pub fn make_graphs(args: &GraphConfig, _config: &Config) -> Result<()> { // Choose action to do match args.target { GraphTargetType::Generate => gen_graph(args), @@ -114,7 +83,7 @@ fn del_graphs(args: &GraphConfig) -> Result<()> { /// Generate the graph and save it fn gen_graph(args: &GraphConfig) -> Result<()> { // Import CSV - let data = include_bytes!("../data/lmroman8-regular.ttf") as &[u8]; + let data = include_bytes!("../../data/lmroman8-regular.ttf") as &[u8]; get_or_try_init_fonts(Some(vec![data])).unwrap(); let csv = import_csv(args)?; @@ -233,36 +202,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/graphs/src/lib.rs b/graphs/src/lib.rs new file mode 100644 index 0000000..f0b501f --- /dev/null +++ b/graphs/src/lib.rs @@ -0,0 +1,9 @@ +//! This workspace_crate is a Rust library designed to create and manage graphs based on CSV (Comma-Separated Values) data. +//! +//! + +// Internal modules +mod graphs; +// +// Re Export +pub use graphs::make_graphs; diff --git a/make/Cargo.toml b/make/Cargo.toml new file mode 100644 index 0000000..3d6aeb6 --- /dev/null +++ b/make/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "make" +version = "0.1.0" +edition = "2024" + +[dependencies] +config = {path = "../config"} +cli_parser = {path = "../cli_parser"} +dynfmt = { version = "0.1.5", features = ["curly"] } +indicatif = { version = "0.17.11", features = ["rayon"] } +logos = "0.15.0" +tokio = "1.43.0" +anyhow = "1.0.95" +indexmap = "2.7.1" +regex = "1.11.1" +serde = { version = "1.0.217", features = ["derive", "alloc"] } +console = "0.15.10" +toml = "0.8.20" diff --git a/make/src/lib.rs b/make/src/lib.rs new file mode 100644 index 0000000..1034e41 --- /dev/null +++ b/make/src/lib.rs @@ -0,0 +1,28 @@ +// Workspace: make +// File: make/src/lib.rs +//! The module `makepdf` is responsible for making a pdf using pdflatex. +//! +//! The main function, [`make_pdf`](crate::makepdf::make_pdf), orchestrates the entire process of preparing, +//! building, and cleaning up LaTeX files to produce a final PDF. It relies on several other modules +//! within the `makepdf` workspace to perform specific tasks. +//! +//! This module contains various helper functions used in the main build process. +//! +//! It provides utilities for checking and adding input lines based on specified conditions, +//! generating glossaries, and managing temporary files. These functions are essential for ensuring +//! that the LaTeX files are correctly prepared before invoking pdflatex to generate the final PDF. +//! +//! Contains utility data types used by other modules in the `makepdf` workspace. +//! +//! This module is responsible for defining the necessary data structures and traits that are shared +//! across different parts of the build process. It includes items such as enums, structs, and traits +//! that help in organizing and managing the various components involved in creating a PDF from LaTeX files. +//! +// Internal modules +mod makepdf; +mod makepdf_functions; +mod makepdf_misc; +mod makepdf_structs; + +// Re Export +pub use makepdf::make_pdf; diff --git a/src/makepdf.rs b/make/src/makepdf.rs similarity index 82% rename from src/makepdf.rs rename to make/src/makepdf.rs index 3e67393..10be675 100644 --- a/src/makepdf.rs +++ b/make/src/makepdf.rs @@ -1,74 +1,47 @@ -//! Make a pdf using pdflatex +// Workspace: make +// File: make/src/makepdf.rs +//! The module `makepdf_functions` is responsible for making a pdf using pdflatex. +//! +//! +//! # Usage +//! +//! - [make_pdf]: Make a pdf spawning a subprocess +//! +//! # Functions +//! +//! - `launch_subprocess`: Launches the subprocess to make the pdf +//! - `checkline`: Checks each line of the subprocess output and updates the status accordingly +//! -use std::time::{Duration, Instant}; -// use std::str::pattern::Pattern; -use std::fmt::Write; +use config::make::{BLOCK_PROGRESSION, HELP_BLOCK_SELECTION, MakeTargets, VerboseLevel}; +use std::{ + fmt::Write, + process::Stdio, + str, + time::{Duration, Instant}, +}; +use cli_parser::{Config, MakeConfig}; use dynfmt::FormatArgs; use indicatif::{ProgressBar, ProgressState, ProgressStyle}; use logos::Logos; -use std::str; -use tokio::io::{AsyncBufReadExt, BufReader}; -use tokio::process::Command; +use tokio::{ + io::{AsyncBufReadExt, BufReader}, + process::Command, +}; -use anyhow::{anyhow, Result}; -use clap::Args; -use std::process::Stdio; +use anyhow::{Result, anyhow}; 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<()> { +pub fn make_pdf(args: &MakeConfig, _config: &Config) -> Result<()> { let Ok(Some(_)) = BLOCK_PROGRESSION.get_key(&args.pbar) else { panic!( "Progressbar {} doesn't exists. Use one of the following [{:?}]", diff --git a/src/makepdf_functions.rs b/make/src/makepdf_functions.rs similarity index 94% rename from src/makepdf_functions.rs rename to make/src/makepdf_functions.rs index 274df5a..60a6b88 100644 --- a/src/makepdf_functions.rs +++ b/make/src/makepdf_functions.rs @@ -1,5 +1,11 @@ -//! Helper functions - +// Workspace: make +// File: make/src/makepdf_functions.rs +//! The module `makepdf_functions` is a collection of helper functions used in the main build process. +//! +//! It provides various utilities for preparing, building, and cleaning up LaTeX files. +//! These functions are primarily responsible for checking and adding input lines based +//! on specified conditions, generating glossaries, and managing temporary files. +//! use std::{ fs::File, io::{Read, Write}, @@ -10,13 +16,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 = @@ -90,6 +94,7 @@ pub(super) fn make_file(args: &MakeConfig) -> BuilderParseResult { } } +/// Execute an external git command macro_rules! exec_cmd { ($cmd:expr, $args:expr) => { { diff --git a/make/src/makepdf_misc.rs b/make/src/makepdf_misc.rs new file mode 100644 index 0000000..161cd38 --- /dev/null +++ b/make/src/makepdf_misc.rs @@ -0,0 +1 @@ +//! Printing and misc utilities diff --git a/src/makepdf_structs.rs b/make/src/makepdf_structs.rs similarity index 94% rename from src/makepdf_structs.rs rename to make/src/makepdf_structs.rs index 2b21796..0e1509e 100644 --- a/src/makepdf_structs.rs +++ b/make/src/makepdf_structs.rs @@ -1,5 +1,9 @@ -//! Holds all the structs for the makepdf module - +// Workspace: make +// File: make/src/makepdf_structs.rs +//! Contains utility data types used by other modules in the `makepdf` workspace. +//! +use cli_parser::MakeConfig; +use config::make::VerboseLevel; use logos::Logos; use serde::{Deserialize, Serialize}; use std::{ @@ -10,7 +14,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