Updates the arg parser
Build Successful The build was successful
Ravenous/ravenous-tools/pipeline/head This commit looks good Details

This commit is contained in:
Dandaedre 2026-07-25 06:22:11 +02:00
parent a3b0f4a744
commit 7f5c09ae36
Signed by: Dandaedre
GPG Key ID: 440C6592E8A26D99
7 changed files with 100 additions and 51 deletions

View File

@ -6,7 +6,7 @@ resolver = "3"
# edition = "2024"
# license = "MIT OR Apache-2.0"
[workspace.package]
version = "0.3.15"
version = "0.3.17"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@ -5,64 +5,107 @@
#![allow(dead_code)]
use anyhow::Result;
use clap::{Args, ValueEnum};
use clap::Args;
use clap::Parser;
use indexmap::IndexMap;
use serde::{Deserialize, Deserializer};
#[derive(Args, Debug, Clone)]
/// The configuration struct for the Graph
/// The top‑level configuration – only a subcommand is needed here.
#[derive(Parser, Debug)]
#[command(
name = "monster",
author,
version,
about = "Export or balance monster data"
)]
pub struct MonsterConfig {
/// Special target
/// Which action to perform
#[command(subcommand)]
pub target: MonsterTarget,
}
/// A special export path
/// The two actions the binary can take.
#[derive(Debug, Parser)]
pub enum MonsterTarget {
/// Generate a tex file(s) with monster lists
Export(ExportArgs),
/// Produce balancing diagnostics
Balance(BalanceArgs),
}
/// Common arguments
#[derive(Debug, Args)]
pub struct CommonDb {
#[arg(
short = 'd',
long = "database",
default_value = "./ravenous_databases/monsters.db",
help = "Path to the SQLite monster database"
)]
/// Database to load from – shared by *both* commands.
pub database: String,
}
#[derive(Debug, Args)]
/// Filter data
pub struct CommonFilter {
#[arg(
long = "filter",
default_value = "show_to_master = 1",
help = "SQL‑like filter applied when querying monsters"
)]
/// Optional data filter – also shared by both commands.
pub filter: Option<String>,
}
#[derive(Debug, Args)]
/// Export only arguments
pub struct ExportArgs {
/// Flatten the shared database flag into this command.
#[clap(flatten)]
pub db: CommonDb,
/// Flatten the shared filter flag into this command.
#[clap(flatten)]
pub filter: CommonFilter,
/// Path where the tex files will be written
#[arg(long, default_value = "./Bestiaire/")]
pub destination: String,
/// Database to load from
#[arg(short, long, default_value = "./ravenous_databases/monsters.db")]
pub database: String,
/// Export the full monsters as full_bestiaire.tex
/// Export *all* monsters (full_bestiaire.tex)
#[arg(long, default_value_t = false)]
pub master: bool,
/// Export the player monsters as player_bestiaire.tex
/// Export only player‑usable monsters
#[arg(long, default_value_t = false)]
pub player: bool,
/// Export both
/// Export both `master` and `player`
#[arg(long, default_value_t = false)]
pub all: bool,
// /// Clean all the artefacts (including generated images)
// #[arg(short, long)]
// pub all: bool,
/// Show extra balancing data
}
#[derive(Debug, Args)]
/// Balance only arguments
pub struct BalanceArgs {
/// Flatten the shared database flag into this command.
#[clap(flatten)]
pub db: CommonDb,
/// Flatten the shared filter flag into this command.
#[clap(flatten)]
pub filter: CommonFilter,
/// Show the raw balancing numbers
#[arg(long, default_value_t = false)]
pub show_extra: bool,
/// Show extra balancing data
/// Show detailed profiles for each monster
#[arg(long, default_value_t = false)]
pub show_profiles: bool,
/// Data filter
#[arg(long, default_value = "show_to_master = 1")]
pub filter: Option<String>,
// /// Defense profile
// #[arg(long, default_value_t=DefenseMode::Best)]
// pub defense_mode: DefenseMode,
}
#[derive(ValueEnum, Debug, Clone)]
/// The action to execute
pub enum MonsterTarget {
// /// Clean the generated monsters directory
// Clean,
/// Generate the monster list
Export,
/// Balancing data
Balance,
}
/// Configuration data for generating a monster sheet.
///
/// The values are plain LaTeX fragments stored in the `[monster]` section of a `.toml`

View File

@ -33,14 +33,19 @@ use rusqlite::Connection;
pub fn monsters_dispatch(args: &MonsterConfig, config: &Config) -> Result<()> {
// use config::monsters::MonsterTarget;
let connection =
Connection::open(&args.database).context(format!("Opening database {}", args.database))?;
match args.target {
// MonsterTarget::Clean => unimplemented!("implement cleaning logic"),
MonsterTarget::Export => generate_monsters_tex(args, config, connection)?,
MonsterTarget::Export(ref args) => {
let connection = Connection::open(&args.db.database)
.context(format!("Opening database {}", args.db.database))?;
generate_monsters_tex(args, config, connection)?
}
// MonsterTarget::Show => unimplemented!("implement show logic"),
MonsterTarget::Balance => show_balancing_data(args, config, connection)?,
MonsterTarget::Balance(ref args) => {
let connection = Connection::open(&args.db.database)
.context(format!("Opening database {}", &args.db.database))?;
show_balancing_data(args, config, connection)?
}
}
Ok(())
}

View File

@ -2,6 +2,7 @@
#![allow(dead_code)]
use comfy_table::modifiers;
use config::monsters::BalanceArgs;
use crate::{
Config, Connection, MonsterConfig,
@ -18,12 +19,12 @@ pub mod monster_analysis_structs;
/// Shows balancing information for monsters and players.
pub fn show_balancing_data(
args: &MonsterConfig,
args: &BalanceArgs,
config: &Config,
connection: Connection,
) -> Result<(), anyhow::Error> {
let _ = args;
let data = fetch_all_creature_data(&connection, config, args.filter.as_deref())?;
let data = fetch_all_creature_data(&connection, config, args.filter.filter.as_deref())?;
let player_data = fetch_all_player_data(&connection, config)?;
for creature in data {

View File

@ -1,5 +1,4 @@
use crate::{
MonsterConfig,
monster_analysis::{
helpers,
monster_analysis_structs::{
@ -8,13 +7,14 @@ use crate::{
},
monster_structs::{PlayerBalancing, ProfileStance},
};
use config::monsters::BalanceArgs;
use more_fields::FieldsAsSlice;
use std::cmp::max;
use std::collections::HashMap;
/// Returns the Balancing profile, and eventually the other profiles as well
pub fn all_attacks(
args: &MonsterConfig,
args: &BalanceArgs,
attack: &monster_analysis_structs::MonsterBalancingAttack,
victims: &HashMap<ProfileStance, PlayerBalancing>,
mode: DefenseMode,

View File

@ -1,5 +1,4 @@
use crate::{
MonsterConfig,
monster_analysis::{
DefenseMode, attack_analysis,
helpers::{binomial_dice_distribution, how_much_with_succeses},
@ -8,11 +7,12 @@ use crate::{
monster_render::ToTable,
monster_structs::{CreatureBodyPart, FullMonster, PlayerBalancing, ProfileHSE, ProfileStance},
};
use config::monsters::BalanceArgs;
use more_fields::FieldsAsSlice;
use std::collections::HashMap;
pub(crate) fn display_player_attacks(
args: &MonsterConfig,
args: &BalanceArgs,
creature: &FullMonster,
profiles: &HashMap<ProfileStance, PlayerBalancing>,
mode: DefenseMode,
@ -209,7 +209,7 @@ pub struct DefenseReport {
}
pub(crate) fn display_monster_attacks(
args: &MonsterConfig,
args: &BalanceArgs,
creature: FullMonster,
profiles: &HashMap<ProfileStance, PlayerBalancing>,
mode: DefenseMode,

View File

@ -2,7 +2,7 @@
use anyhow::{Context, Result};
use cli_parser::Config;
use config::monsters::MonsterConfig;
use config::monsters::{ExportArgs, MonsterConfig};
use handlebars::{Handlebars, handlebars_helper};
use indexmap::IndexMap;
use rusqlite::Connection;
@ -40,11 +40,11 @@ fn load_templates(config: &Config) -> Result<Handlebars<'_>> {
/// Export a tex with the given config and arguments
pub fn generate_monsters_tex(
args: &MonsterConfig,
args: &ExportArgs,
config: &Config,
connection: Connection,
) -> std::result::Result<(), anyhow::Error> {
let all_monsters = fetch_all_creature_data(&connection, config, args.filter.as_deref())?;
let all_monsters = fetch_all_creature_data(&connection, config, args.filter.filter.as_deref())?;
let templates = load_templates(config)?;
println!("Processing");
let mut m_out = String::new();