From 3132cd98f5cac2d18e742cfa7a5ddac16b06fa9e Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Thu, 27 Jun 2024 22:38:15 +0200 Subject: [PATCH] Fix unhelpful help --- src/table_structs.rs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/table_structs.rs b/src/table_structs.rs index 741d52b..be8f819 100644 --- a/src/table_structs.rs +++ b/src/table_structs.rs @@ -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, @@ -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 = 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)] @@ -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 ) } }