Added base harness
Build Successful The build was successful
Gitea/epoch_forge/pipeline/head This commit looks good Details

This commit is contained in:
Dandaedre 2025-11-15 23:04:33 +01:00
parent 466ad9f98c
commit ee53efd695
3 changed files with 48 additions and 154 deletions

View File

@ -1,4 +1,3 @@
// efo/src/commands/epoch.rs
//! # `epoch` sub‑command
//!
//! Handles all epoch‑related logic – logging, switching, computing the
@ -7,13 +6,9 @@
use std::str::FromStr;
use clap::{Args, Subcommand, error::ErrorKind};
use lib_efo::epoch_struct::EpochId;
use lib_efo::{epoch_struct::EpochId, error::EpochError};
use serde::{Deserialize, Serialize};
// use crate::storage::JsonStore;
// use crate::storage::StoreTrait; // abstraction for persistence
// use crate::world::World; // the domain model // concrete store (used only for the stub)
/// The outer clap entry that the binary will dispatch to
#[derive(Subcommand, Debug)]
pub enum EpochCmd {
@ -97,102 +92,41 @@ impl FromStr for EpochIdentifier {
}
}
}
// /// **Public entry point used by `efo::main`** – dispatches to the real
// /// handler that lives in `crate::world::EpochManager`.
// pub fn handle_cmd(cmd: EpochCmd, world: &mut World) -> anyhow::Result<()> {
// match cmd {
// EpochCmd::Log(args) => handle_log(args, world),
// EpochCmd::Switch(args) => handle_switch(args, world),
// EpochCmd::Next(_) => handle_next(world),
// EpochCmd::Reset(_) => handle_reset(world),
// }
// }
/// **Public entry point used by `efo::main`** – dispatches to the real
/// handler that lives in `crate::world::EpochManager`.
pub fn handle_cmd(cmd: EpochCmd) -> Result<(), EpochError> {
match cmd {
EpochCmd::Log(args) => handle_log(args),
EpochCmd::Switch(args) => handle_switch(args),
EpochCmd::Next(_) => handle_next(),
EpochCmd::Reset(_) => handle_reset(),
}
}
// /// ---------- helpers ----------
fn handle_log(_args: Log) -> Result<(), EpochError> {
// NOTE: `world.epoch_manager` already owns the schedule.
println!("Epoch log (most recent first):");
// println!(
// "#{} {} [{}] {}",
// epoch.id, epoch.date, tags, epoch.summary
// );
Ok(())
}
// fn handle_log(_args: Log, world: &World) -> anyhow::Result<()> {
// // NOTE: `world.epoch_manager` already owns the schedule.
// println!("Epoch log (most recent first):");
// for epoch in world.epoch_manager.schedule.iter().rev() {
// // a tiny human‑friendly representation
// let tags = epoch.tags.join(", ");
// println!(
// "#{} {} [{}] {}",
// epoch.id, epoch.date, tags, epoch.summary
// );
// }
// Ok(())
// }
fn handle_switch(args: Switch) -> Result<(), EpochError> {
// Resolve the target – we allow ID, name, or tag
// fn handle_switch(args: Switch, world: &mut World) -> anyhow::Result<()> {
// // Resolve the target – we allow ID, name, or tag
// let target_id = world.epoch_manager.resolve(&args.target, args.force)?;
println!("Switched to epoch {:?}", args.target);
Ok(())
}
// world.set_epoch(target_id);
// println!(
// "Switched to epoch #{} – {}",
// target_id,
// world.current_context().date
// );
// Ok(())
// }
fn handle_next() -> Result<(), EpochError> {
println!("⚡ Next",);
Ok(())
}
// fn handle_next(world: &mut World) -> anyhow::Result<()> {
// // 1️⃣ No future events? → OK
// // 2️⃣ Future events → error (branching TBD)
// if world
// .epoch_manager
// .schedule
// .iter()
// .any(|e| e.id > world.epoch_manager.current.id)
// {
// anyhow::bail!("❌ Cannot compute `next` – future events still pending");
// }
// world.epoch_manager.advance_to_next()?;
// println!(
// "⚡ Advanced to epoch #{} – {}",
// world.epoch_manager.current.id,
// world.current_context().date
// );
// Ok(())
// }
// fn handle_reset(world: &mut World) -> anyhow::Result<()> {
// // After a `switch`, erase all future events
// world.clear_future_events()?;
// println!(
// "✅ All future events deleted – back to epoch #{}",
// world.epoch_manager.current.id
// );
// Ok(())
// }
//
//
// pub fn handle_cmd(cmd: EpochCmd, world: &mut World) -> Result<()> {
// match cmd {
// EpochCmd::Log(_) => {
// for e in world.epoch_manager.schedule.iter().rev() {
// println!("#{} {} [{}] {}", e.id, e.date, e.tags.join(","), e.summary);
// }
// }
// EpochCmd::Switch(SwitchArgs { target, force }) => {
// let id = world.epoch_manager.resolve(&target, force)?;
// world.set_epoch(id);
// println!("🔀 Switched to epoch #{}", id);
// }
// EpochCmd::Next(_) => {
// if world.epoch_manager.has_future_events() {
// anyhow::bail!("Cannot run `next`: future events still pending");
// }
// world.compute_next_epoch()?;
// println!("⚡ Advanced to epoch #{}", world.epoch_manager.current.id);
// }
// EpochCmd::Reset(_) => {
// world.clear_future_events()?;
// println!("🗑 All future events deleted – back at epoch #{}", world.epoch_manager.current.id);
// }
// }
// Ok(())
// }
fn handle_reset() -> Result<(), EpochError> {
// After a `switch`, erase all future events
println!("✅ All future events deleted – back to epoch",);
Ok(())
}

View File

@ -3,11 +3,9 @@
//! `AppError` aggregates all error kinds that may surface during a command
//! execution: parsing, I/O, epoch logic, storage, and a catch‑all.
use lib_efo::error::StorageError;
use lib_efo::error::{EpochError, StorageError};
use thiserror::Error;
use crate::commands::error::EpochError;
/// All errors that can bubble up to the CLI.
#[derive(Debug, Error)]
#[allow(dead_code)]

View File

@ -17,56 +17,19 @@
//!
//! ## Usage
//! ```sh
//! efo org add --name "The Iron Horde" --leader "Gorun"
//! efo epoch --advance 5
//! efo link add --type alliance --org "Iron Horde" --town "Durn"
//! efo epoch switch 5
//! ```
// use clap::{Parser, Subcommand};
// mod cli;
use clap::{Parser, Subcommand};
use crate::{commands::epoch::EpochCmd, error::AppError};
mod commands;
mod error;
// use commands::EpochCmd;
// use commands::*;
// #[derive(Parser)]
// #[command(name = "efo")]
// #[command(about = "Epoch Forge – manage organisations over time")]
// struct Opts {
// #[command(subcommand)]
// cmd: Subcommands,
// }
// #[derive(Subcommand)]
// enum Subcommands {
// Epoch(commands::epoch::EpochCmd),
// Event(commands::event::EventCmd),
// Org(commands::org::OrgCmd),
// Chr(commands::chr::ChrCmd),
// Town(commands::town::TownCmd),
// Link(commands::link::LinkCmd),
// }
// fn main() {
// let opts = Opts::parse();
// match opts.cmd {
// Subcommands::Epoch(c) => c.handle(),
// Subcommands::Event(c) => c.handle(),
// Subcommands::Org(c) => c.handle(),
// Subcommands::Chr(c) => c.handle(),
// Subcommands::Town(c) => c.handle(),
// Subcommands::Link(c) => c.handle(),
// }
// }
/// Root parser – the “efo” program
#[derive(Parser, Debug)]
#[command(name = "efo")]
#[command(about = "Epoch Forge – manage organisations over time")]
struct Cli {
#[command(subcommand)]
command: TopLevelCmd,
@ -78,22 +41,21 @@ enum TopLevelCmd {
#[command(subcommand)]
Epoch(EpochCmd),
// … other sub‑commands (org, event, etc.)
// Event(commands::event::EventCmd),
// Org(commands::org::OrgCmd),
// Chr(commands::chr::ChrCmd),
// Town(commands::town::TownCmd),
// Link(commands::link::LinkCmd),
}
fn main() -> Result<(), AppError> {
// let cli = Cli::parse();
let cli = Cli::parse();
// // Load the world (you’ll probably want a proper store here)
// let store = crate::storage::JsonStore::new(PathBuf::from("./data"));
// let mut world = store.load_world(); // async‑aware
// match cli.command {
// TopLevelCmd::Epoch(cmd) => {
// commands::epoch::handle_cmd(cmd, &mut world)?;
// store.persist_world(&world).await?; // write back if anything changed
// } // … other top‑level cases …
// }
match cli.command {
TopLevelCmd::Epoch(cmd) => {
commands::epoch::handle_cmd(cmd)?;
}
}
Ok(())
}