ravenous-tools/crates/cli_parser/src/lib.rs

148 lines
4.0 KiB
Rust

//! The usual cli parser shenenigans
//!
#![warn(missing_docs, clippy::missing_docs_in_private_items)]
use clap::{Args, Parser, Subcommand};
use config::{
analysis::AnalysisConfig,
fast_tables::FastTableConfig,
formatter::FormatterConfig,
graph::GraphConfig,
make::{HELP_BLOCK_SELECTION, MakeTargets, VerboseLevel},
monsters::{MonsterConfig, MonsterMarkup},
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),
/// Format the file given on input
Format(FormatterConfig),
/// Generate analysis data
Analysis(AnalysisConfig),
/// Better Generation
BetterGen(FastTableConfig),
/// Monster database handling
Monsters(MonsterConfig),
}
#[derive(Debug, Args)]
/// Genrate the config file with the specified arguments
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<String>,
}
#[derive(Deserialize)]
/// The config struct, holding all runtime information
pub struct Config {
/// Config specific for data generation
pub data_generation: Datagen,
/// Config specific for the classes table generation
pub classes: Classes,
/// Config for all the tables
pub craft: Craft,
/// Config for monster exporting
pub monster: MonsterMarkup,
}
#[derive(Deserialize)]
/// The classes config
pub struct Classes {
/// 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,
}
#[derive(Deserialize)]
/// The data generation configuration
pub struct Datagen {
/// Where to find the data generation database
pub database: String,
}
// The make structs
#[derive(Args, Debug, Clone)]
/// The configuration struct for the PdfMaker
pub struct MakeConfig {
/// The filename to compile
pub filename: String,
/// Special target
#[arg(short, long)]
pub target: Option<MakeTargets>,
/// The verbosity level
#[arg(short, long, default_value = "warning")]
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<String>,
/// Deselect these targets
#[arg(short, long, value_name = "FILE", group = "select")]
pub no: Vec<String>,
/// 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,
/// The pdflatex command
#[arg(short, long, default_value_t = String::from("pdflatex"))]
pub latex_command: String,
}