Adds logging
Build Failed The build failed
Gitea/epoch_forge/pipeline/head There was a failure building this commit
Details
Build Failed The build failed
Gitea/epoch_forge/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
1edd0ea67e
commit
ac8f3fafe7
|
|
@ -17,6 +17,15 @@ version = "2.0.1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"
|
||||
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "1.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstream"
|
||||
version = "0.6.21"
|
||||
|
|
@ -96,7 +105,9 @@ name = "bin_efo"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"env_logger",
|
||||
"lib_efo",
|
||||
"log",
|
||||
"miette",
|
||||
"serde",
|
||||
"serde_json",
|
||||
|
|
@ -226,6 +237,29 @@ dependencies = [
|
|||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "env_filter"
|
||||
version = "0.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1bf3c259d255ca70051b30e2e95b5446cdb8949ac4cd22c0d7fd634d89f568e2"
|
||||
dependencies = [
|
||||
"log",
|
||||
"regex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "env_logger"
|
||||
version = "0.11.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "13c863f0904021b108aa8b2f55046443e6b1ebde8fd4a15c399893aae4fa069f"
|
||||
dependencies = [
|
||||
"anstream",
|
||||
"anstyle",
|
||||
"env_filter",
|
||||
"jiff",
|
||||
"log",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "errno"
|
||||
version = "0.3.14"
|
||||
|
|
@ -266,6 +300,30 @@ version = "1.0.15"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
|
||||
|
||||
[[package]]
|
||||
name = "jiff"
|
||||
version = "0.2.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "49cce2b81f2098e7e3efc35bc2e0a6b7abec9d34128283d7a26fa8f32a6dbb35"
|
||||
dependencies = [
|
||||
"jiff-static",
|
||||
"log",
|
||||
"portable-atomic",
|
||||
"portable-atomic-util",
|
||||
"serde_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "jiff-static"
|
||||
version = "0.2.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "980af8b43c3ad5d8d349ace167ec8170839f753a42d233ba19e08afe1850fa69"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lib_efo"
|
||||
version = "0.1.0"
|
||||
|
|
@ -273,6 +331,8 @@ dependencies = [
|
|||
"clap",
|
||||
"cli-table",
|
||||
"derive_more",
|
||||
"env_logger",
|
||||
"log",
|
||||
"miette",
|
||||
"serde",
|
||||
"serde_json",
|
||||
|
|
@ -291,6 +351,12 @@ version = "0.11.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "df1d3c3b53da64cf5760482273a98e575c651a67eec7f77df96b5b642de8f039"
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.28"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "34080505efa8e45a4b816c349525ebe327ceaa8559756f0356cba97ef3bf7432"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.7.6"
|
||||
|
|
@ -357,6 +423,21 @@ version = "4.2.3"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9c6901729fa79e91a0913333229e9ca5dc725089d1c363b2f4b4760709dc4a52"
|
||||
|
||||
[[package]]
|
||||
name = "portable-atomic"
|
||||
version = "1.11.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f84267b20a16ea918e43c6a88433c2d54fa145c92a811b5b047ccbe153674483"
|
||||
|
||||
[[package]]
|
||||
name = "portable-atomic-util"
|
||||
version = "0.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d8a2f0d8d040d7848a709caf78912debcc3f33ee4b3cac47d73d1e1069e83507"
|
||||
dependencies = [
|
||||
"portable-atomic",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.103"
|
||||
|
|
@ -375,6 +456,35 @@ dependencies = [
|
|||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.12.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "843bc0191f75f3e22651ae5f1e72939ab2f72a4bc30fa80a066bd66edefc24d4"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-automata",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-automata"
|
||||
version = "0.4.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5276caf25ac86c8d810222b3dbb938e512c55c6831a10f3e6ed1c93b84041f1c"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.8.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7a2d987857b319362043e95f5353c0535c1f58eec5336fdfcf626430af7def58"
|
||||
|
||||
[[package]]
|
||||
name = "rustc-demangle"
|
||||
version = "0.1.26"
|
||||
|
|
|
|||
|
|
@ -8,3 +8,5 @@ clap = { version = "4.5.51", features = ["derive"] }
|
|||
thiserror = "2.0.17"
|
||||
serde_json = "1.0.145"
|
||||
miette = { version = "7.6.0", features = ["fancy"] }
|
||||
env_logger = "0.11.8"
|
||||
log = "0.4.28"
|
||||
|
|
|
|||
|
|
@ -10,3 +10,5 @@ clap = {workspace = true}
|
|||
thiserror = {workspace = true}
|
||||
serde_json = {workspace = true}
|
||||
miette = {workspace = true}
|
||||
env_logger = {workspace = true}
|
||||
log = {workspace = true}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
use crate::error::AppError;
|
||||
use lib_efo::{epoch_struct::EpochConfig, epoch_traits::ConfigWritable, error::EpochError};
|
||||
use log::{debug, info};
|
||||
|
||||
pub mod cli_epoch;
|
||||
|
||||
|
|
@ -14,7 +15,7 @@ pub mod cli_epoch;
|
|||
pub fn handle_cmd(cmd: cli_epoch::EpochCmd) -> Result<(), AppError> {
|
||||
let mut main_epoch = EpochConfig::new_from_path(None)?;
|
||||
// // TODO[2]: Remove this debug
|
||||
// println!("The main epoch is {:#?}", main_epoch);
|
||||
debug!("The main epoch befor any action is {:#?}", main_epoch);
|
||||
match cmd {
|
||||
cli_epoch::EpochCmd::Log(args) => handle_log(args, &mut main_epoch),
|
||||
cli_epoch::EpochCmd::Switch(args) => handle_switch(args, &mut main_epoch),
|
||||
|
|
@ -25,8 +26,7 @@ pub fn handle_cmd(cmd: cli_epoch::EpochCmd) -> Result<(), AppError> {
|
|||
cli_epoch::EpochCmd::Fsck(args) => handle_fsck(args, &mut main_epoch),
|
||||
}?;
|
||||
|
||||
// // TODO[2]: Remove this debug
|
||||
// println!("The main epoch is {:#?}", main_epoch);
|
||||
info!("The main epoch after all actions is {:#?}", main_epoch);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
@ -38,6 +38,7 @@ fn handle_diff(args: cli_epoch::Diff) -> Result<(), AppError> {
|
|||
|
||||
/// Show a log of all different epochs
|
||||
fn handle_log(args: cli_epoch::Log, main_epoch: &mut EpochConfig) -> Result<(), AppError> {
|
||||
// TODO: Have a special centralized message dispacher
|
||||
println!("Epoch log (most recent first):");
|
||||
let limit = args.limit;
|
||||
let start_id = &main_epoch.epoch_id;
|
||||
|
|
@ -51,7 +52,6 @@ fn handle_log(args: cli_epoch::Log, main_epoch: &mut EpochConfig) -> Result<(),
|
|||
.copied()
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
// TODO[8]: Consider other ways to log than one element at a time
|
||||
main_epoch.log_elements(&list_id)?;
|
||||
|
||||
Ok(())
|
||||
|
|
@ -70,6 +70,7 @@ fn handle_switch(args: cli_epoch::Switch, main_epoch: &mut EpochConfig) -> Resul
|
|||
main_epoch.try_load(&target)?;
|
||||
main_epoch.epoch_id = target;
|
||||
|
||||
// TODO: Have a special centralized message dispacher
|
||||
println!("Switched to epoch {:?}", target);
|
||||
main_epoch.save_with_context(
|
||||
"Saving modified epoch config",
|
||||
|
|
@ -140,6 +141,7 @@ fn handle_reset(args: cli_epoch::Reset, main_epoch: &mut EpochConfig) -> Result<
|
|||
{
|
||||
main_epoch.delete_id(id)?
|
||||
}
|
||||
// TODO: Have a special centralized message dispacher
|
||||
println!("All future events deleted – back to epoch {current_id}",);
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,6 +69,7 @@ enum TopLevelCmd {
|
|||
/// sub‑command. Errors returned by the sub‑command handlers are printed
|
||||
/// to stdout and returned as a `miette::Result<()>`.
|
||||
fn main() -> miette::Result<()> {
|
||||
env_logger::init();
|
||||
let cli = Cli::parse();
|
||||
|
||||
if let Err(e) = exec_dispatch(cli) {
|
||||
|
|
@ -95,6 +96,7 @@ fn exec_dispatch(cli: Cli) -> Result<(), AppError> {
|
|||
match cli.command {
|
||||
TopLevelCmd::Init(cmd) => {
|
||||
commands::init::init(&cmd)?;
|
||||
// TODO: Have a special centralized message dispacher
|
||||
println!("The folder was initialized as an epoch folder")
|
||||
}
|
||||
TopLevelCmd::Epoch(cmd) => {
|
||||
|
|
|
|||
|
|
@ -9,5 +9,7 @@ serde = {workspace = true}
|
|||
thiserror = {workspace = true}
|
||||
clap = {workspace = true}
|
||||
miette = {workspace = true}
|
||||
env_logger = {workspace = true}
|
||||
log = {workspace = true}
|
||||
derive_more = { version = "2.0.1", features = ["display"] }
|
||||
cli-table = "0.5.0"
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ use std::{
|
|||
path::Path,
|
||||
};
|
||||
|
||||
use log::info;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
|
|
@ -98,8 +99,7 @@ impl EpochConfig {
|
|||
let elt = io_err_with_help!(elt, "Opening file in main config folder")?;
|
||||
if io_err_with_help!(elt.file_type(), "Determining file type of {:?}", elt)?.is_dir() {
|
||||
let id = elt.file_name().to_string_lossy().parse::<EpochId>();
|
||||
// TODO: Logging
|
||||
// println!("Initialized {:?}", id);
|
||||
info!("Initialized {:?}", id);
|
||||
self.list_existing_epochs.insert(id.unwrap(), None);
|
||||
}
|
||||
}
|
||||
|
|
@ -192,15 +192,16 @@ impl EpochConfig {
|
|||
"The given epoch {} doesn't exists and it's deletion was skipped",
|
||||
id
|
||||
)
|
||||
} else {
|
||||
io_err_with_help!(
|
||||
remove_dir_all(EpochInfo::with_id(&id).save_folder()),
|
||||
"Removing the epoch {}",
|
||||
id
|
||||
)?;
|
||||
self.list_existing_epochs.remove(&id);
|
||||
self.tags.retain(|_k, v| *v != id);
|
||||
self.save_with_context("Saving after delete_id", &SaveMode::Erase)?;
|
||||
}
|
||||
io_err_with_help!(
|
||||
remove_dir_all(EpochInfo::with_id(&id).save_folder()),
|
||||
"Removing the epoch {}",
|
||||
id
|
||||
)?;
|
||||
self.list_existing_epochs.remove(&id);
|
||||
self.tags.retain(|_k, v| *v != id);
|
||||
self.save_with_context("Saving after delete_id", &SaveMode::Erase)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
@ -212,7 +213,7 @@ impl EpochConfig {
|
|||
pub fn compute_next(&mut self) -> Result<EpochInfo, EpochError> {
|
||||
// unimplemented!()
|
||||
// TODO[1]: Implement this
|
||||
print!("DEBUG LINE: COMPUTING NEXT EPOCH");
|
||||
println!("DEBUG LINE: COMPUTING NEXT EPOCH");
|
||||
// New fake epoch
|
||||
Ok(EpochInfo::with_id(&self.epoch_id.next()))
|
||||
}
|
||||
|
|
@ -254,9 +255,11 @@ impl EpochConfig {
|
|||
/// loaded into memory, then prints a formatted log for each one.
|
||||
pub fn log_elements(&mut self, list_ids: &[EpochId]) -> Result<(), EpochError> {
|
||||
let mut items_to_log = Vec::with_capacity(list_ids.len());
|
||||
// Tries to load all ids into memory
|
||||
for id in list_ids {
|
||||
self.try_load(id)?;
|
||||
}
|
||||
// Makes a vector with all elements from the list of ids
|
||||
for id in list_ids {
|
||||
if let Some(info) = self
|
||||
.list_existing_epochs
|
||||
|
|
@ -266,10 +269,7 @@ impl EpochConfig {
|
|||
items_to_log.push(info);
|
||||
}
|
||||
}
|
||||
// items_to_log[0].as_log()
|
||||
for item in items_to_log {
|
||||
item.show_as_log();
|
||||
}
|
||||
EpochInfo::show_as_table(items_to_log);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
//! seed that produced the world, any optional tags, and a human‑readable
|
||||
//! summary. World data itself is stored separately (e.g. in `world.json`).
|
||||
|
||||
use cli_table::Table;
|
||||
use cli_table::{Table, WithTitle};
|
||||
use derive_more::Display;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fs::create_dir_all;
|
||||
|
|
@ -55,11 +55,8 @@ pub struct EpochInfo {
|
|||
}
|
||||
|
||||
impl Prettiable for EpochInfo {
|
||||
fn show_as_table(list: Vec<Self>)
|
||||
where
|
||||
Self: std::marker::Sized,
|
||||
{
|
||||
cli_table::print_stdout(list).unwrap();
|
||||
fn show_as_table(list: Vec<&Self>) {
|
||||
cli_table::print_stdout(list.with_title()).unwrap();
|
||||
}
|
||||
|
||||
fn as_log(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -26,10 +26,7 @@ pub trait Nextable {}
|
|||
pub trait Prettiable {
|
||||
// TODO: Doc
|
||||
/// Show many as a table
|
||||
fn show_as_table(list: Vec<Self>)
|
||||
where
|
||||
Self: std::marker::Sized,
|
||||
{
|
||||
fn show_as_table(list: Vec<&Self>) {
|
||||
list.iter().for_each(|e| {
|
||||
e.show_as_log();
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue