Skip to content

Commit

Permalink
feat(ark-cli): add watch command to use fs-index watch api
Browse files Browse the repository at this point in the history
Signed-off-by: Tarek <[email protected]>
  • Loading branch information
tareknaser committed Sep 9, 2024
1 parent 1d35318 commit 6aa9e49
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ark-cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ mod list;
mod monitor;
mod render;
pub mod storage;
mod watch;

pub use file::{file_append, file_insert, format_file, format_line};

Expand All @@ -18,6 +19,7 @@ pub enum Commands {
Monitor(monitor::Monitor),
Render(render::Render),
List(list::List),
Watch(watch::Watch),
#[command(about = "Manage links")]
Link {
#[clap(subcommand)]
Expand Down
27 changes: 27 additions & 0 deletions ark-cli/src/commands/watch.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use std::path::PathBuf;

use fs_index::watch_index;

use crate::{AppError, ResourceId};

#[derive(Clone, Debug, clap::Args)]
#[clap(
name = "watch",
about = "Watch the ark managed folder for changes and update the index accordingly"
)]
pub struct Watch {
#[clap(
help = "Path to the directory to watch for changes",
default_value = ".",
value_parser
)]
path: PathBuf,
}

impl Watch {
pub async fn run(&self) -> Result<(), AppError> {
watch_index::<_, ResourceId>(&self.path)
.await
.map_err(|err| AppError::IndexError(err.to_string()))
}
}
1 change: 1 addition & 0 deletions ark-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ async fn run() -> Result<()> {
Monitor(monitor) => monitor.run()?,
Render(render) => render.run()?,
List(list) => list.run()?,
Watch(watch) => watch.run().await?,
Link { subcommand } => match subcommand {
Create(create) => create.run().await?,
Load(load) => load.run()?,
Expand Down

0 comments on commit 6aa9e49

Please sign in to comment.