diff --git a/bin_efo/src/commands/generate.rs b/bin_efo/src/commands/generate.rs index b071ce8..4d2819f 100644 --- a/bin_efo/src/commands/generate.rs +++ b/bin_efo/src/commands/generate.rs @@ -1,11 +1,28 @@ -//! Subcommand for fast generating ideas and displaying them -//! This module does not add any structure (that would be either the prerogative of the bulk generator or the individual modules) +//! # Generation Sub‑command +//! +//! This module implements the `gen` sub‑command used to quickly produce +//! sample data for the various generators in *lib_efo*. The command has no +//! side‑effects beyond printing the generated data; it is intended for +//! interactive use or for embedding in scripts. +//! +//! ## Available sub‑commands +//! +//! * `character` – Generate character names (long or short). +//! * `event` – Generate event ideas. +//! * `town` – Generate town names. +//! * `exotic` – Generate exotic character names. +//! +//! Each sub‑command accepts a set of common options (see [`Qty`]) that +//! control how many items are produced and how they are displayed. +//! use clap::{Args, Subcommand}; use lib_efo::{Displayable, error::EpochError, naming::NAMING}; use crate::error::AppError; -/// The types of examples to generate +/// The types of examples to generate. +/// +/// Each variant maps directly to a public sub‑command of the `gen` tool. #[derive(Subcommand, Debug)] pub enum GenCmd { /// Generate a character @@ -19,16 +36,38 @@ pub enum GenCmd { } #[derive(Args, Debug)] +/// Common arguments for the generation subcommands. +/// +/// The fields are deliberately named to match the command‑line flags +/// produced by `clap`. The struct is used by all sub‑commands to +/// keep the CLI surface area minimal. pub struct Qty { - /// Amount of entities to generate + /// Amount of entities to generate. #[arg(short, long, default_value_t = 1)] number: usize, - /// Full print + /// Full print. + /// + /// If set to `false` the generator will produce a *short* representation #[arg(long, action = clap::ArgAction::SetFalse, default_value_t = true)] short: bool, + /// Generate only a name, no underlying structure. + /// + /// When this flag is present the generator prints only the name string + /// rather than any additional data or formatting. + #[arg(long="name", action = clap::ArgAction::SetTrue, default_value_t = false)] + name_only: bool, } -/// Handle all the generation +/// Handles the subcommand for generating various kinds of entities. +/// +/// Depending on the selected variant of [`GenCmd`], it delegates to the +/// corresponding private handler function. +/// +/// # Arguments +/// * `cmd` - The parsed subcommand arguments. +/// +/// # Errors +/// Returns an [`AppError`] if any of the underlying handlers fail. pub fn gen_handler(cmd: &GenCmd) -> Result<(), AppError> { match cmd { GenCmd::Character(args) => handle_chr(args)?, @@ -42,7 +81,12 @@ pub fn gen_handler(cmd: &GenCmd) -> Result<(), AppError> { /// Prints exotic name fn handle_exotic(args: &Qty) -> Result<(), EpochError> { for _ in 0..args.number { - println!("{}", NAMING.generate_exotic_character_name()) + let name = NAMING.generate_exotic_character_name(); + if args.name_only { + println!("{}", name); + } else { + unimplemented!("DEPENS ON : CHARACTER CREATION") + } } Ok(()) } @@ -50,7 +94,12 @@ fn handle_exotic(args: &Qty) -> Result<(), EpochError> { /// Prints town fn handle_town(args: &Qty) -> Result<(), EpochError> { for _ in 0..args.number { - println!("{}", NAMING.generate_town_name()) + let name = NAMING.generate_town_name(); + if args.name_only { + println!("{}", name); + } else { + unimplemented!("DEPENS ON : TOWN CREATION") + } } Ok(()) } @@ -58,7 +107,12 @@ fn handle_town(args: &Qty) -> Result<(), EpochError> { /// Print events fn handle_event(args: &Qty) -> Result<(), EpochError> { for _ in 0..args.number { - println!("{}", NAMING.random_event_idea()?.oneline_display()); + let event = NAMING.random_event_idea()?; + if args.name_only { + println!("{}", event.name); + } else { + println!("{}", event.oneline_display()); + } } Ok(()) } @@ -66,10 +120,16 @@ fn handle_event(args: &Qty) -> Result<(), EpochError> { /// Print a character name fn handle_chr(args: &Qty) -> Result<(), EpochError> { for _ in 0..args.number { - if args.short { - println!("{}", NAMING.generate_long_character_name()) + let name = if args.short { + NAMING.generate_long_character_name() } else { - println!("{}", NAMING.generate_character_name()) + NAMING.generate_character_name() + }; + + if args.name_only { + println!("{}", name); + } else { + unimplemented!("DEPENS ON : CHARACTER CREATION") } } Ok(()) diff --git a/bin_efo/src/commands/show.rs b/bin_efo/src/commands/show.rs index 39575d0..e55ef46 100644 --- a/bin_efo/src/commands/show.rs +++ b/bin_efo/src/commands/show.rs @@ -1,7 +1,7 @@ //! The show commands //! Used to display structures with various degree of verbosity -use clap::Subcommand; +use clap::{Args, Subcommand}; use lib_efo::{Displayable, entity::Entity, naming::NAMING}; use crate::error::AppError; @@ -10,8 +10,17 @@ use crate::error::AppError; pub enum ShowCmd { /// Show an event Event, + /// Show an event + Character, + /// Show an event + Town, } +// #[derive(Args)] +// struct Specifics { +// name: String, +// } + /// Handle all show cmds pub fn handle_show_cmd(cmd: &ShowCmd) -> Result<(), AppError> { let _ = cmd; @@ -36,3 +45,7 @@ pub fn handle_show_cmd(cmd: &ShowCmd) -> Result<(), AppError> { Ok(()) } + +// Show event +// Show diff (char/town) +// Show .... diff --git a/lib_efo/src/naming.rs b/lib_efo/src/naming.rs index d9e230f..17b1249 100644 --- a/lib_efo/src/naming.rs +++ b/lib_efo/src/naming.rs @@ -83,7 +83,7 @@ impl Displayable for EventDescription { let mut line2 = "│ └─ Stats: ".to_string(); for effect in &self.stats { - line2.push_str(&format!("{}:{} ", effect.stat.to_symbol(), effect.value,)); + line2.push_str(&format!("{}:{} ", effect.stat.to_shortest(), effect.value,)); } format!("{line1}\n{line2}") diff --git a/lib_efo/src/stats/implementations.rs b/lib_efo/src/stats/implementations.rs index 13f85f5..7e183ea 100644 --- a/lib_efo/src/stats/implementations.rs +++ b/lib_efo/src/stats/implementations.rs @@ -241,7 +241,7 @@ impl FromStr for StatPair { } impl Symbols for EntityType { - fn to_symbol(&self) -> String { + fn to_shortest(&self) -> String { match self { EntityType::Character => "[C]".to_string(), EntityType::Player => "[P]".to_string(), @@ -251,6 +251,16 @@ impl Symbols for EntityType { EntityType::Event => "[E]".to_string(), } } + fn to_symbol(&self) -> String { + match self { + EntityType::Character => "".to_string(), + EntityType::Player => " ".to_string(), + EntityType::Town => "󱡵 ".to_string(), + EntityType::Monster => " ".to_string(), + EntityType::Blocker => " ".to_string(), + EntityType::Event => "".to_string(), + } + } } impl Symbols for EffectApplication { @@ -299,31 +309,61 @@ impl Symbols for OverallStats { } impl Symbols for ListStats { + fn to_shortest(&self) -> String { + match self { + ListStats::Demographics => "Dem".blue(), + ListStats::Population => "Pop".green(), + ListStats::Growthrate => "Gro".green(), + ListStats::Crime => "Cri".green(), + ListStats::Happiness => "Hap".green(), + ListStats::Economy => "Eco".blue(), + ListStats::Food => "Foo".yellow(), + ListStats::Industry => "Ind".yellow(), + ListStats::Science => "Sci".yellow(), + ListStats::Trade => "Tra".yellow(), + ListStats::Social => "Soc".blue(), + ListStats::Culture => "Cul".purple(), + ListStats::Education => "Edu".purple(), + ListStats::Tourism => "Tou".purple(), + ListStats::Influence => "Inf".purple(), + ListStats::Military => "Mil".blue(), + ListStats::Army => "Arm".red(), + ListStats::Strength => "Str".red(), + ListStats::Fortification => "For".red(), + ListStats::Threat => "Thr".red(), + ListStats::Infrastructure => "Inf".blue(), + ListStats::Bureaucracy => "Bur".cyan(), + ListStats::Transportation => "Tra".cyan(), + ListStats::Sprawl => "Spr".cyan(), + ListStats::Health => "Hea".cyan(), + } + .to_string() + } fn to_symbol(&self) -> String { match self { - ListStats::Demographics => "".blue(), - ListStats::Population => "".green(), - ListStats::Growthrate => "".green(), + ListStats::Demographics => " ".blue(), + ListStats::Population => " ".green(), + ListStats::Growthrate => " ".green(), ListStats::Crime => "󱀣".green(), - ListStats::Happiness => "".green(), + ListStats::Happiness => " ".green(), ListStats::Economy => "💰".blue(), ListStats::Food => "󰔬".yellow(), ListStats::Industry => "🏭".yellow(), - ListStats::Science => "󰧑".yellow(), - ListStats::Trade => "".yellow(), - ListStats::Social => "󱕹".blue(), + ListStats::Science => "󰧑 ".yellow(), + ListStats::Trade => " ".yellow(), + ListStats::Social => "󱕹 ".blue(), ListStats::Culture => "🎭".purple(), ListStats::Education => "📚".purple(), ListStats::Tourism => "🏖️".purple(), ListStats::Influence => "🌍".purple(), ListStats::Military => "🪖".blue(), - ListStats::Army => "".red(), - ListStats::Strength => "󰞇".red(), + ListStats::Army => " ".red(), + ListStats::Strength => "󰞇 ".red(), ListStats::Fortification => "🔒".red(), ListStats::Threat => "⚡".red(), - ListStats::Infrastructure => "🏗️".blue(), - ListStats::Bureaucracy => "🏛️".cyan(), - ListStats::Transportation => "󰔬".cyan(), + ListStats::Infrastructure => "🏗️ ".blue(), + ListStats::Bureaucracy => "🏛️ ".cyan(), + ListStats::Transportation => "󰔬 ".cyan(), ListStats::Sprawl => "🏙️".cyan(), ListStats::Health => "".cyan(), }