More on show

This commit is contained in:
Dandaedre 2025-12-02 20:31:57 +01:00
parent 7ec2622959
commit f121f12eb1
6 changed files with 2426 additions and 35 deletions

View File

@ -10,6 +10,7 @@
pub mod epoch;
pub mod init;
pub mod show;
// pub mod diff;
// pub mod utils;
// pub mod event;

View File

@ -38,7 +38,7 @@ pub mod cli_epoch;
///
/// The function never panics under normal operation. All errors are
/// reported via the returned `Result`.
pub fn handle_cmd(cmd: cli_epoch::EpochCmd) -> Result<(), AppError> {
pub fn handle_cmd(cmd: &cli_epoch::EpochCmd) -> Result<(), AppError> {
let mut main_epoch = EpochConfig::new_from_path(None)?;
// // TODO[2]: Remove this debug
debug!("The main epoch befor any action is {:#?}", main_epoch);
@ -66,14 +66,17 @@ pub fn handle_cmd(cmd: cli_epoch::EpochCmd) -> Result<(), AppError> {
///
/// This helper is internal to the `epoch` sub-command and is not part
/// of the public API.
fn handle_summary(args: cli_epoch::Summary, main_epoch: &mut EpochConfig) -> Result<(), AppError> {
fn handle_summary(args: &cli_epoch::Summary, main_epoch: &mut EpochConfig) -> Result<(), AppError> {
let epoch_id = main_epoch.epoch_id;
main_epoch.try_load(&epoch_id)?;
#[allow(clippy::unwrap_used)] // The epoch_id must exists at this point
if let Some(epoch) = main_epoch.list_existing_epochs.get_mut(&epoch_id).unwrap() {
epoch.summary = args.summary.clone();
epoch.save_with_context("Saving new summary", &lib_efo::epoch::SaveMode::Erase)?;
display_success(&SuccessMessages::ChangedSummary(epoch_id, args.summary));
display_success(&SuccessMessages::ChangedSummary(
epoch_id,
args.summary.clone(),
));
}
Ok(())
@ -86,7 +89,7 @@ fn handle_summary(args: cli_epoch::Summary, main_epoch: &mut EpochConfig) -> Res
///
/// This helper is internal to the `epoch` sub-command and is not part
/// of the public API.
fn handle_diff(args: cli_epoch::Diff) -> Result<(), AppError> {
fn handle_diff(args: &cli_epoch::Diff) -> Result<(), AppError> {
let _ = args;
unimplemented!("Blocker: There is actually no way to diff the world yet")
}
@ -100,7 +103,7 @@ fn handle_diff(args: cli_epoch::Diff) -> Result<(), AppError> {
/// underlying `EpochConfig::log_elements` implementation.
///
/// This helper is internal to the `epoch` sub-command.
fn handle_log(args: cli_epoch::Log, main_epoch: &mut EpochConfig) -> Result<(), AppError> {
fn handle_log(args: &cli_epoch::Log, main_epoch: &mut EpochConfig) -> Result<(), AppError> {
let limit = args.limit;
let start_id = &main_epoch.epoch_id;
@ -122,7 +125,7 @@ fn handle_log(args: cli_epoch::Log, main_epoch: &mut EpochConfig) -> Result<(),
/// success message via `display_success`.
///
/// This helper is internal to the `epoch` sub-command.
fn handle_switch(args: cli_epoch::Switch, main_epoch: &mut EpochConfig) -> Result<(), AppError> {
fn handle_switch(args: &cli_epoch::Switch, main_epoch: &mut EpochConfig) -> Result<(), AppError> {
let target = main_epoch.get(&args.target)?;
main_epoch.try_load(&target)?;
main_epoch.epoch_id = target;
@ -150,7 +153,7 @@ fn handle_switch(args: cli_epoch::Switch, main_epoch: &mut EpochConfig) -> Resul
/// * `Ok(())` if the next epoch was successfully computed.
/// * `Err(AppError::Epoch(EpochError::FutureEpochExist))` if there are
/// no future epochs to advance to.
fn handle_next(_args: cli_epoch::Next, main_epoch: &mut EpochConfig) -> Result<(), AppError> {
fn handle_next(_args: &cli_epoch::Next, main_epoch: &mut EpochConfig) -> Result<(), AppError> {
let current_id = main_epoch.epoch_id;
// Check that there are no future epochs
@ -183,7 +186,7 @@ fn handle_next(_args: cli_epoch::Next, main_epoch: &mut EpochConfig) -> Result<(
/// # Returns
/// * `Ok(())` if all future epochs were successfully removed.
/// * `Err(AppError)` if any deletion fails.
fn handle_reset(args: cli_epoch::Reset, main_epoch: &mut EpochConfig) -> Result<(), AppError> {
fn handle_reset(args: &cli_epoch::Reset, main_epoch: &mut EpochConfig) -> Result<(), AppError> {
let _ = args;
let current_id = main_epoch.epoch_id;
// for id in main_epoch
@ -217,7 +220,7 @@ fn handle_reset(args: cli_epoch::Reset, main_epoch: &mut EpochConfig) -> Result<
/// already exists in another epoch.
/// * `Err(AppError::Epoch(EpochError::Unknown))` if the epoch cannot
/// be found or saved.
fn handle_taging(args: cli_epoch::Tag, main_epoch: &mut EpochConfig) -> Result<(), AppError> {
fn handle_taging(args: &cli_epoch::Tag, main_epoch: &mut EpochConfig) -> Result<(), AppError> {
// Load into memory the current epoch
main_epoch.try_load(&main_epoch.epoch_id.clone())?;
@ -263,7 +266,7 @@ fn handle_taging(args: cli_epoch::Tag, main_epoch: &mut EpochConfig) -> Result<(
/// command may also print a diagnostic message to the user.
///
/// This helper is internal to the `epoch` sub-command.
fn handle_fsck(args: cli_epoch::Fsck, main_epoch: &mut EpochConfig) -> Result<(), AppError> {
fn handle_fsck(args: &cli_epoch::Fsck, main_epoch: &mut EpochConfig) -> Result<(), AppError> {
let _ = main_epoch;
let _ = args;
unimplemented!()

View File

@ -0,0 +1,38 @@
//! The show commands
//!
use clap::Subcommand;
use lib_efo::{Displayable, entity::Entity, naming::NAMING};
use crate::error::AppError;
#[derive(Subcommand, Debug)]
/// Show command
pub enum ShowCmd {
/// Show an event
Event,
}
/// Handle all show cmds
pub fn handle_show_cmd(cmd: &ShowCmd) -> Result<(), AppError> {
let _ = cmd;
let mut e = Entity::default();
e.name = NAMING.generate_long_character_name();
println!("Original Struct: \n{e:#?}");
println!("\n\n\nONELINES");
println!("{}", e.oneline_display());
println!("{}", e.oneline_display());
println!("{}", e.oneline_display());
println!("{}", e.oneline_display());
println!("{}", e.oneline_display());
println!("{}", e.oneline_display());
println!("{}", e.oneline_display());
println!("\n\n\n SHORT");
e.print_short();
println!("\n\n\n LONG");
e.print_full();
println!("\n\n\n TREE");
println!("{}", e.to_pretty_tree());
Ok(())
}

View File

@ -23,12 +23,14 @@
#![warn(missing_docs, clippy::missing_docs_in_private_items)]
#![deny(clippy::unwrap_used)]
use clap::{ArgAction, Parser, Subcommand};
use lib_efo::Displayable;
use lib_efo::entity::Entity;
use std::fmt::Debug;
use crate::commands::init::InitCmd;
use crate::{commands::epoch::cli_epoch::EpochCmd, error::AppError};
use clap::{ArgAction, Parser, Subcommand};
use crate::{
commands::{epoch::cli_epoch::EpochCmd, init::InitCmd, show::ShowCmd},
error::AppError,
};
mod commands;
mod error;
mod success;
@ -61,6 +63,9 @@ enum TopLevelCmd {
/// Advance or query the current epoch.
#[command(subcommand)]
Epoch(EpochCmd),
/// Display some elements
#[command(subcommand)]
Show(ShowCmd),
// Event(commands::event::EventCmd),
// Org(commands::org::OrgCmd),
// Chr(commands::chr::ChrCmd),
@ -77,18 +82,6 @@ enum TopLevelCmd {
fn main() -> miette::Result<()> {
env_logger::init();
let e = Entity::default();
// println!("{e:#?}");
println!("{}", e.oneline_display());
println!("{}", e.oneline_display());
println!("{}", e.oneline_display());
println!("{}", e.oneline_display());
println!("{}", e.oneline_display());
println!("{}", e.oneline_display());
println!("{}", e.oneline_display());
// e.print_short();
// e.print_full();
// println!("{}", e.to_pretty_tree());
let cli = Cli::parse();
if let Err(e) = exec_dispatch(cli) {
@ -113,12 +106,8 @@ fn main() -> miette::Result<()> {
/// stdout and returned as a `miette::Result<()>`.
fn exec_dispatch(cli: Cli) -> Result<(), AppError> {
match cli.command {
TopLevelCmd::Init(cmd) => {
commands::init::init(&cmd)?;
}
TopLevelCmd::Epoch(cmd) => {
commands::epoch::handle_cmd(cmd)?;
}
TopLevelCmd::Init(cmd) => commands::init::init(&cmd),
TopLevelCmd::Epoch(cmd) => commands::epoch::handle_cmd(&cmd),
TopLevelCmd::Show(cmd) => commands::show::handle_show_cmd(&cmd),
}
Ok(())
}

View File

@ -22,7 +22,7 @@ pub mod implementations;
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct Entity {
/// The name of the entity
name: String,
pub name: String,
/// Runtime statistics that determine the entity’s behaviour.
///
/// These values are updated by the game loop and reflect the

2360
naming.json Normal file

File diff suppressed because it is too large Load Diff