Fix unhelpful help

This commit is contained in:
Dandaedre 2024-06-27 22:38:15 +02:00
parent c344e96517
commit 3132cd98f5
1 changed files with 15 additions and 5 deletions

View File

@ -3,7 +3,7 @@ use clap::Args;
use phf::phf_map;
use regex::Regex;
use serde::Deserialize;
use std::fmt::Debug;
use std::{fmt::Debug, sync::LazyLock};
use regex_static::once_cell::sync::Lazy;
@ -43,12 +43,12 @@ pub(super) struct Craft {
/// Configuration options for processing TSV files and generating LaTeX tables.
#[derive(Debug, Args)]
pub(super) struct TableArgs {
/// A boolean indicating whether to generate LaTeX code and write it to an output file
/// (if true) or just print the generated code to stdout
/// 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<String>,
@ -75,6 +75,16 @@ static STR_TO_TARGET: phf::Map<&'static str, TableGenerationTarget> = phf_map! {
"all" => TableGenerationTarget::All,
};
/// A help of all the table targets to be built
pub(super) static HELP_STR_TO_TARGET_TABLES: LazyLock<String> = LazyLock::new(|| {
let mut targets = STR_TO_TARGET
.keys()
.map(|v| v.to_string())
.collect::<Vec<String>>();
targets.sort();
targets.join(", ").to_string()
});
/// All the type of tsv that can be processed by the program
// #[enum_dispatch]
#[derive(Clone)]
@ -128,8 +138,8 @@ impl From<&str> for TableGenerationTarget {
target
} else {
panic!(
"Only the following target can be used: {:?}",
STR_TO_TARGET.keys()
"Only the following target can be used: {}",
*HELP_STR_TO_TARGET_TABLES
)
}
}