Generate skeleton
This commit is contained in:
parent
f121f12eb1
commit
417da3d617
|
|
@ -9,6 +9,7 @@
|
|||
#![warn(missing_docs, clippy::missing_docs_in_private_items)]
|
||||
|
||||
pub mod epoch;
|
||||
pub mod generate;
|
||||
pub mod init;
|
||||
pub mod show;
|
||||
// pub mod diff;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,18 @@
|
|||
//! 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)
|
||||
|
||||
use clap::Subcommand;
|
||||
|
||||
use crate::error::AppError;
|
||||
/// The types of examples to generate
|
||||
#[derive(Subcommand, Debug)]
|
||||
pub enum GenCmd {
|
||||
/// Generate a character
|
||||
Character,
|
||||
}
|
||||
|
||||
/// Handle all the generation
|
||||
pub fn gen_handler(cmd: &GenCmd) -> Result<(), AppError> {
|
||||
let _ = cmd;
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
//! The show commands
|
||||
//!
|
||||
//! Used to display structures with various degree of verbosity
|
||||
|
||||
use clap::Subcommand;
|
||||
use lib_efo::{Displayable, entity::Entity, naming::NAMING};
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ use std::fmt::Debug;
|
|||
use clap::{ArgAction, Parser, Subcommand};
|
||||
|
||||
use crate::{
|
||||
commands::{epoch::cli_epoch::EpochCmd, init::InitCmd, show::ShowCmd},
|
||||
commands::{epoch::cli_epoch::EpochCmd, generate::GenCmd, init::InitCmd, show::ShowCmd},
|
||||
error::AppError,
|
||||
};
|
||||
mod commands;
|
||||
|
|
@ -71,6 +71,9 @@ enum TopLevelCmd {
|
|||
// Chr(commands::chr::ChrCmd),
|
||||
// Town(commands::town::TownCmd),
|
||||
// Link(commands::link::LinkCmd),
|
||||
#[command(subcommand)]
|
||||
/// Generate random structures and display them
|
||||
Gen(GenCmd),
|
||||
}
|
||||
|
||||
/// Program entry point.
|
||||
|
|
@ -78,7 +81,6 @@ enum TopLevelCmd {
|
|||
/// Parses the command-line arguments and dispatches to the selected
|
||||
/// sub-command. Errors returned by the sub-command handlers are shown
|
||||
/// in stdout and returned as a `miette::Result<()>`.
|
||||
#[allow(clippy::unwrap_used)]
|
||||
fn main() -> miette::Result<()> {
|
||||
env_logger::init();
|
||||
|
||||
|
|
@ -109,5 +111,6 @@ fn exec_dispatch(cli: Cli) -> Result<(), AppError> {
|
|||
TopLevelCmd::Init(cmd) => commands::init::init(&cmd),
|
||||
TopLevelCmd::Epoch(cmd) => commands::epoch::handle_cmd(&cmd),
|
||||
TopLevelCmd::Show(cmd) => commands::show::handle_show_cmd(&cmd),
|
||||
TopLevelCmd::Gen(cmd) => commands::generate::gen_handler(&cmd),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -217,6 +217,17 @@ pub enum EpochError {
|
|||
#[error("An user facing error")]
|
||||
#[diagnostic(code(EpochError::UserError))]
|
||||
UserError(#[help] UserErrors),
|
||||
|
||||
/// An error happened when picking a rng event
|
||||
#[error("An error happened when trying to pick a rng event for {cause}")]
|
||||
#[diagnostic(code(EpochError::RNGPickError))]
|
||||
RNGPickError {
|
||||
/// The root cause originating the error
|
||||
cause: String,
|
||||
#[help]
|
||||
/// Optionnal help
|
||||
help: Option<String>,
|
||||
},
|
||||
}
|
||||
|
||||
/// A small enum of explicit user-facing error messages.
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ use std::path::{Path, PathBuf};
|
|||
use crate::entity::EffectApplication;
|
||||
use crate::entity::EffectBounds;
|
||||
use crate::entity::EntityDuration;
|
||||
use crate::error::EpochError;
|
||||
use crate::stats::StatPair;
|
||||
|
||||
/// The structure that holds everything we need for name generation.
|
||||
|
|
@ -86,9 +87,9 @@ impl NamingData {
|
|||
pub fn generate_character_name(&self) -> String {
|
||||
let mut rng = rand::rng();
|
||||
|
||||
let binding = "Unnamed".into();
|
||||
let binding = "Bobman".into();
|
||||
let first = self.first_names.choose(&mut rng).unwrap_or(&binding);
|
||||
let binding = "".into();
|
||||
let binding = "McBobintown".into();
|
||||
let last = self.last_names.choose(&mut rng).unwrap_or(&binding);
|
||||
format!("{} {}", first, last).trim().to_string()
|
||||
}
|
||||
|
|
@ -96,17 +97,22 @@ impl NamingData {
|
|||
/// Generate a random **town** name.
|
||||
pub fn generate_town_name(&self) -> String {
|
||||
let mut rng = rand::rng();
|
||||
let binding = "".into();
|
||||
let binding = "Bobtown".into();
|
||||
let prefix = self.town_prefixes.choose(&mut rng).unwrap_or(&binding);
|
||||
let suffix = self.town_suffixes.choose(&mut rng).unwrap_or(&binding);
|
||||
format!("{}{}", prefix, suffix).trim().to_string()
|
||||
}
|
||||
|
||||
/// Pick a random event idea (you can reuse this or make a dedicated method).
|
||||
/// Pick a random event idea
|
||||
#[allow(clippy::unwrap_used)]
|
||||
pub fn random_event_idea(&self) -> &EventDescription {
|
||||
pub fn random_event_idea(&self) -> Result<&EventDescription, EpochError> {
|
||||
let mut rng = rand::rng();
|
||||
self.event_ideas.choose(&mut rng).unwrap()
|
||||
self.event_ideas
|
||||
.choose(&mut rng)
|
||||
.ok_or(EpochError::RNGPickError {
|
||||
cause: "Picking a random event".into(),
|
||||
help: None,
|
||||
})
|
||||
}
|
||||
|
||||
/// Generates something like:
|
||||
|
|
|
|||
Loading…
Reference in New Issue