Adds most of next and delete logic
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
e1453090d4
commit
413cc09758
|
|
@ -26,7 +26,11 @@ pub fn handle_cmd(cmd: cli_epoch::EpochCmd) -> Result<(), AppError> {
|
|||
cli_epoch::EpochCmd::Diff(args) => handle_diff(args),
|
||||
cli_epoch::EpochCmd::Tag(args) => handle_taging(args, &mut main_epoch),
|
||||
cli_epoch::EpochCmd::Fsck(args) => handle_fsck(args, &mut main_epoch),
|
||||
}
|
||||
}?;
|
||||
|
||||
// TODO: Remove this debug
|
||||
println!("The main epoch is {:#?}", main_epoch);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Show the diff between two epochs
|
||||
|
|
@ -115,14 +119,17 @@ fn handle_next(_args: cli_epoch::Next, main_epoch: &mut EpochConfig) -> Result<(
|
|||
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
|
||||
for id in main_epoch
|
||||
.list_existing_epochs
|
||||
.keys()
|
||||
.filter(|&k| k > ¤t_id)
|
||||
.copied()
|
||||
// Middle step necessary for borrowing purposes
|
||||
.collect::<Vec<_>>()
|
||||
{
|
||||
main_epoch.delete_id(*id)?
|
||||
main_epoch.delete_id(id)?
|
||||
}
|
||||
|
||||
println!("All future events deleted – back to epoch {current_id}",);
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,8 +75,6 @@ fn main() -> miette::Result<()> {
|
|||
// AppError::Storage(storage_error) => todo!(),
|
||||
// AppError::Other(_) => todo!(),
|
||||
// }
|
||||
println!("The program didn't exit properly and returned the following error:");
|
||||
// println!("{}", e);
|
||||
Err(e)?;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -121,7 +121,10 @@ impl EpochConfig {
|
|||
/// Try to load into memory the given epoch id
|
||||
pub fn try_load(&mut self, epoch_id: &EpochId) -> Result<(), EpochError> {
|
||||
// Preload the epoch
|
||||
let value = self.list_existing_epochs.get_mut(epoch_id).unwrap();
|
||||
let value = self
|
||||
.list_existing_epochs
|
||||
.get_mut(epoch_id)
|
||||
.ok_or(EpochError::EpochNotFound(format!("{epoch_id}")))?;
|
||||
|
||||
// Create a mock epoch
|
||||
let path = EpochInfo::with_id(epoch_id).save_path();
|
||||
|
|
@ -166,7 +169,8 @@ impl EpochConfig {
|
|||
}
|
||||
|
||||
/// Tries to delete an entire epoch folder by Id
|
||||
pub fn delete_id(&self, id: EpochId) -> Result<(), EpochError> {
|
||||
// TODO: Create a delete_ids taking an iterator for added performance on huge deletions
|
||||
pub fn delete_id(&mut self, id: EpochId) -> Result<(), EpochError> {
|
||||
if !self.list_existing_epochs.contains_key(&id) {
|
||||
println!(
|
||||
"The given epoch {} doesn't exists and it's deletion was skipped",
|
||||
|
|
@ -178,6 +182,9 @@ impl EpochConfig {
|
|||
"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(())
|
||||
}
|
||||
|
||||
|
|
@ -201,18 +208,15 @@ impl EpochConfig {
|
|||
return Err(EpochError::EpochAlreadyExists(new_epoch.epoch_id));
|
||||
}
|
||||
|
||||
// TODO: Finish
|
||||
new_epoch
|
||||
.save_with_context("Saving new epoch without subfolders", save_mode)
|
||||
.unwrap();
|
||||
new_epoch.create_subfolders().unwrap();
|
||||
new_epoch.create_subfolders().unwrap();
|
||||
new_epoch.create_subfolders().unwrap();
|
||||
new_epoch
|
||||
.save_with_context("Saving new epoch", save_mode)
|
||||
.unwrap();
|
||||
new_epoch.create_subfolders()?;
|
||||
new_epoch.save_with_context("Saving new epoch", save_mode)?;
|
||||
|
||||
// Add the epoch to the list of epochs
|
||||
// Add the epoch to the list of epochs, not doing so will still have it added
|
||||
// at the next iteration since the command always parse the files to determine it's state rater that the list
|
||||
// not doing so would likely create errors if insert is used before another command
|
||||
self.list_existing_epochs
|
||||
.insert(new_epoch.epoch_id, Some(new_epoch));
|
||||
self.save_with_context("Saving after insert_and_save", &SaveMode::Erase)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue