Adds a all target
This commit is contained in:
parent
dc84016969
commit
2dd8d54c3b
|
|
@ -41,27 +41,30 @@ pub(crate) struct TableArgs {
|
|||
pub export: bool,
|
||||
|
||||
/// The kind of tables to operate on: classes, craft or files followed by a list of files
|
||||
pub kind: TableGenerationTarge,
|
||||
pub kind: TableGenerationTarget,
|
||||
/// A vector of strings representing the names of TSV files to process.
|
||||
pub filenames: Vec<String>,
|
||||
}
|
||||
|
||||
/// An enumeration representing different target types.
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum TableGenerationTarge {
|
||||
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,
|
||||
}
|
||||
|
||||
/// A mapping of string representations to target types.
|
||||
static STR_TO_TARGET: phf::Map<&'static str, TableGenerationTarge> = phf_map! {
|
||||
"classes" => TableGenerationTarge::Classes,
|
||||
"craft" => TableGenerationTarge::Craft,
|
||||
"files" => TableGenerationTarge::Files,
|
||||
static STR_TO_TARGET: phf::Map<&'static str, TableGenerationTarget> = phf_map! {
|
||||
"classes" => TableGenerationTarget::Classes,
|
||||
"craft" => TableGenerationTarget::Craft,
|
||||
"files" => TableGenerationTarget::Files,
|
||||
"all" => TableGenerationTarget::All,
|
||||
};
|
||||
|
||||
/// All the type of tsv that can be processed by the program
|
||||
|
|
@ -107,7 +110,7 @@ pub(crate) static STR_TO_TARGET_FULL: phf::Map<&'static str, TableTargets> = phf
|
|||
/// The regex for finding and replacing all stars with a custom DD
|
||||
pub(crate) static RE: Lazy<Regex> = regex_static::lazy_regex!(r"★+");
|
||||
|
||||
impl From<&str> for TableGenerationTarge {
|
||||
impl From<&str> for TableGenerationTarget {
|
||||
fn from(value: &str) -> Self {
|
||||
if let Some(target) = STR_TO_TARGET.get(value).cloned() {
|
||||
target
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ use std::{
|
|||
|
||||
use crate::table_types::{ClassesArray, GenericArray, RecordClass, WriteRow, WriteTable};
|
||||
use crate::{
|
||||
table_structs::{TableArgs, TableGenerationTarge, TableTargets, RE, STR_TO_TARGET_FULL},
|
||||
table_structs::{TableArgs, TableGenerationTarget, TableTargets, RE, STR_TO_TARGET_FULL},
|
||||
Config,
|
||||
};
|
||||
|
||||
|
|
@ -21,30 +21,38 @@ use crate::{
|
|||
/// In charge of the dispatch and the whole conversion
|
||||
pub fn table_gen(args: &TableArgs, config: &Config) -> Result<()> {
|
||||
let list_files = match args.kind {
|
||||
TableGenerationTarge::Classes => {
|
||||
TableGenerationTarget::Classes => {
|
||||
println!("Processing files in the Tables/ subdirectory");
|
||||
&mut list_dir("Tables/???-*.tsv")
|
||||
}
|
||||
TableGenerationTarge::Craft => {
|
||||
TableGenerationTarget::Craft => {
|
||||
println!("Processing files in the Craft/ subdirectory");
|
||||
&mut list_dir("Craft/???-*.tsv")
|
||||
}
|
||||
// Add the use of glob to save the poor windows users
|
||||
TableGenerationTarge::Files => {
|
||||
TableGenerationTarget::Files => {
|
||||
println!("Processing the files given as argument");
|
||||
&mut args.filenames.iter().map(PathBuf::from).collect()
|
||||
}
|
||||
TableGenerationTarget::All => &mut {
|
||||
println!("Processing files in the Tables and Craft subdirectory");
|
||||
let mut targets = list_dir("Tables/???-*.tsv");
|
||||
targets.append(&mut list_dir("Craft/???-*.tsv"));
|
||||
targets
|
||||
},
|
||||
};
|
||||
|
||||
if list_files.is_empty() {
|
||||
println!("No files to process ... skipping");
|
||||
}
|
||||
match args.kind {
|
||||
TableGenerationTarge::Classes => process_files(list_files, args, config),
|
||||
TableGenerationTarge::Craft => process_files(list_files, args, config),
|
||||
// For now every file is considered as a class file
|
||||
TableGenerationTarge::Files => process_files(list_files, args, config),
|
||||
}
|
||||
// match args.kind {
|
||||
// TableGenerationTarget::Classes => process_files(list_files, args, config),
|
||||
// TableGenerationTarget::Craft => process_files(list_files, args, config),
|
||||
// // For now every file is considered as a class file
|
||||
// TableGenerationTarget::Files => process_files(list_files, args, config),
|
||||
// TableGenerationTarget::All =>process_files(list_files, args, config),
|
||||
// }
|
||||
process_files(list_files, args, config)
|
||||
}
|
||||
|
||||
/// Process any type of file, one by one and call the right converter function
|
||||
|
|
@ -142,12 +150,12 @@ pub fn make_latex_string(arg: &str) -> String {
|
|||
.replace('⧆', "\\contondant")
|
||||
.replace('Ø', "\\o{}")
|
||||
.replace('⌭', "\\torque")
|
||||
.replace('☆', "\\star")
|
||||
.replace('☆', "\\ddzero")
|
||||
.replace('🗘', "\\reload")
|
||||
.replace('½', "\\sfrac{1}{2}")
|
||||
.replace('&', "\\&");
|
||||
let res = RE.replace_all(&temp, |caps: &Captures| {
|
||||
format!("\\dd{{{}}}", caps[0].chars().count())
|
||||
format!("\\ddlevel{{{}}}", caps[0].chars().count())
|
||||
});
|
||||
res.to_string()
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue