Files
hyperlog/crates/hyperlog-tui/src/commands/archive.rs
kjuulh 20190ac784
All checks were successful
continuous-integration/drone/push Build is passing
feat: add markdown editing mode
Signed-off-by: kjuulh <contact@kjuulh.io>
2024-06-30 17:31:25 +02:00

58 lines
1.5 KiB
Rust

use itertools::Itertools;
use crate::{
commander::{self, Commander},
models::{IOEvent, Msg},
state::SharedState,
};
pub struct ArchiveCommand {
commander: Commander,
}
impl ArchiveCommand {
pub fn new(commander: Commander) -> Self {
Self { commander }
}
pub fn command(self, root: &str, path: &[&str]) -> super::Command {
let root = root.to_owned();
let path = path.iter().map(|s| s.to_string()).collect_vec();
super::Command::new(|dispatch| {
tokio::spawn(async move {
dispatch.send(Msg::Archive(IOEvent::Initialized));
match self
.commander
.execute(commander::Command::Archive { root, path })
.await
{
Ok(()) => {
#[cfg(debug_assertions)]
{
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
}
dispatch.send(Msg::Archive(IOEvent::Success(())));
}
Err(e) => {
dispatch.send(Msg::Archive(IOEvent::Failure(e.to_string())));
}
}
});
None
})
}
}
pub trait ArchiveCommandExt {
fn archive_command(&self) -> ArchiveCommand;
}
impl ArchiveCommandExt for SharedState {
fn archive_command(&self) -> ArchiveCommand {
ArchiveCommand::new(self.commander.clone())
}
}