From a51523865139b7104ef49d7374ca040229b75ce3 Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Sun, 23 Jun 2024 20:14:50 +0200 Subject: [PATCH] Fixes some of the jank --- src/makepdf.rs | 6 +++-- src/makepdf_functions.rs | 49 ++++++++++++++++++++++++++++++++-------- 2 files changed, 44 insertions(+), 11 deletions(-) diff --git a/src/makepdf.rs b/src/makepdf.rs index 49edf44..2966b7a 100644 --- a/src/makepdf.rs +++ b/src/makepdf.rs @@ -16,7 +16,9 @@ use clap::Args; use std::process::Stdio; use crate::makepdf_functions::{make_clean, make_file, make_glossaries, make_list}; -use crate::makepdf_misc::{BLOCK_PROGRESSION, HELP_BLOCK_SELECTION, HELP_VERBOSITY_LEVEL}; +use crate::makepdf_misc::{ + BLOCK_PROGRESSION, HELP_BLOCK_SELECTION, HELP_BUILD_TARGET_LIST, HELP_VERBOSITY_LEVEL, +}; use crate::makepdf_structs::{ BuildInfo, LineType, MakeTargets, Status, VerboseLevel, COL_NORMAL, TXT_BOXX, TXT_CNTX, TXT_CRIT, TXT_ERRR, TXT_INFO, TXT_MISC, TXT_UKNW, TXT_WARN, @@ -31,7 +33,7 @@ pub(crate) struct MakeConfig { pub(crate) filename: String, /// Special target - #[arg(short, long)] + #[arg(short, long, help = format!("Build with a special target. {}", HELP_BUILD_TARGET_LIST.as_str()))] pub(crate) target: Option, /// The verbosity level diff --git a/src/makepdf_functions.rs b/src/makepdf_functions.rs index 2082c1b..2a9dc25 100644 --- a/src/makepdf_functions.rs +++ b/src/makepdf_functions.rs @@ -11,7 +11,10 @@ use std::{ use anyhow::Result; use regex::Regex; -use crate::makepdf::MakeConfig; +use crate::{ + makepdf::MakeConfig, + makepdf_structs::{COL_ERROR, COL_INFO, COL_MISC, COL_WARNING}, +}; /// Regex detecting wether an input line is present static INPUT_REGEX: LazyLock = @@ -26,18 +29,28 @@ pub(crate) fn make_file(args: &MakeConfig) -> String { let mut contents = String::new(); // Warn about wrong keys - // clear_keys(&mut args); + clear_keys(args, &m); f.read_to_string(&mut contents).unwrap(); for line in contents.lines() { if let Some(c) = INPUT_REGEX.captures(line) { // Check wether it should be added if add_checker(&c[1], &m, args) { - println!("[PREP] Including {}", &c[1]); + println!( + "{} {} {}", + COL_INFO.apply_to("[PREP]"), + COL_MISC.apply_to("Including"), + &c[1] + ); of.write_all(line.as_bytes()).unwrap(); of.write_all("\n".as_bytes()).unwrap(); } else { - println!("[PREP] Excluding {}", &c[1]); + println!( + "{} {} {}", + COL_INFO.apply_to("[PREP]"), + COL_WARNING.apply_to("Excluding"), + &c[1] + ); } } else { of.write_all(line.as_bytes()).unwrap(); @@ -47,11 +60,29 @@ pub(crate) fn make_file(args: &MakeConfig) -> String { format!("{:?}", &path) } -// fn clear_keys(args: &mut &MakeConfig) -> _ { -// for k in args.only{ -// if -// } -// } +/// Clear the list of keys (for now only warn) +fn clear_keys(args: &MakeConfig, dict_entries: &HashMap) { + for k in args.only.iter() { + if !dict_entries.contains_key(k) { + panic!( + "{} The key {} wasn't in the list of togglable imports {:?} rerun with option -t list for the full list", + COL_ERROR.apply_to("[ERRR]"), + k, + dict_entries.keys() + ) + } + } + for k in args.no.iter() { + if !dict_entries.contains_key(k) { + panic!( + "{} The key {} wasn't in the list of togglable imports {:?} rerun with option -t list for the full list", + COL_ERROR.apply_to("[ERRR]"), + k, + dict_entries.keys() + ) + } + } +} /// Algorithm to check wether to add or not the entry fn add_checker(check: &str, dict_entries: &HashMap, args: &MakeConfig) -> bool { -- 2.45.1