feat: add archive

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
2024-05-09 17:02:06 +02:00
parent 9ceaa4cd38
commit 56a63dbb7d
6 changed files with 56 additions and 10 deletions

View File

@@ -25,6 +25,10 @@ pub enum Command {
description: String,
state: ItemState,
},
ToggleItem {
root: String,
path: Vec<String>,
},
Move {
root: String,
src: Vec<String>,
@@ -81,6 +85,9 @@ impl Commander {
&src.iter().map(|p| p.as_str()).collect::<Vec<_>>(),
&dest.iter().map(|p| p.as_str()).collect::<Vec<_>>(),
)?,
Command::ToggleItem { root, path } => self
.engine
.toggle_item(&root, &path.iter().map(|p| p.as_str()).collect::<Vec<_>>())?,
}
self.storage.store(&self.engine)?;

View File

@@ -2,7 +2,7 @@ use std::{collections::BTreeMap, fmt::Display};
use anyhow::{anyhow, Context};
use crate::log::{Graph, GraphItem};
use crate::log::{Graph, GraphItem, ItemState};
#[derive(Default)]
pub struct Engine {
@@ -129,6 +129,22 @@ impl Engine {
.map(|_| ())
.ok_or(anyhow!("item was not found"))
}
pub fn toggle_item(&mut self, root: &str, path: &[&str]) -> anyhow::Result<()> {
if let Some(item) = self.get_mut(root, path) {
match item {
GraphItem::Item { state, .. } => match state {
ItemState::NotDone => *state = ItemState::Done,
ItemState::Done => *state = ItemState::NotDone,
},
_ => {
anyhow::bail!("{}.{:?} is not an item", root, path)
}
}
}
Ok(())
}
}
impl Display for Engine {

View File

@@ -43,4 +43,10 @@ impl SharedEngine {
.unwrap()
.section_move(root, src_path, dest_path)
}
pub fn toggle_item(&self, root: &str, path: &[&str]) -> anyhow::Result<()> {
self.inner.write().unwrap().toggle_item(root, path)?;
Ok(())
}
}