Update dependencies and add new features for improved functionality

- Updated Cargo.lock and Cargo.toml to include new dependencies
- Added new files for backup and watcher functionality in libmarlin
- Introduced integration tests and documentation updates
- Set workspace resolver to version 2 for better dependency resolution
This commit is contained in:
thePR0M3TH3AN
2025-05-19 18:14:42 -04:00
parent 6125acb4d1
commit 2f97bd8c3f
23 changed files with 2567 additions and 50 deletions

View File

@@ -9,6 +9,7 @@ pub mod remind;
pub mod annotate;
pub mod version;
pub mod event;
pub mod watch;
use clap::{Parser, Subcommand, ValueEnum};
use clap_complete::Shell;
@@ -123,6 +124,10 @@ pub enum Commands {
/// Calendar events & timelines
#[command(subcommand)]
Event(event::EventCmd),
/// Watch directories for changes
#[command(subcommand)]
Watch(watch::WatchCmd),
}
#[derive(Subcommand, Debug)]

102
cli-bin/src/cli/watch.rs Normal file
View File

@@ -0,0 +1,102 @@
// src/cli/watch.rs
use anyhow::Result;
use clap::Subcommand;
use libmarlin::watcher::{WatcherConfig, WatcherState};
use rusqlite::Connection;
use std::path::PathBuf;
use std::sync::Arc;
use std::sync::atomic::{AtomicBool, Ordering};
use std::thread;
use std::time::{Duration, Instant};
use tracing::info;
/// Commands related to file watching functionality
#[derive(Subcommand, Debug)]
pub enum WatchCmd {
/// Start watching a directory for changes
Start {
/// Directory to watch (defaults to current directory)
#[arg(default_value = ".")]
path: PathBuf,
/// Debounce window in milliseconds (default: 100ms)
#[arg(long, default_value = "100")]
debounce_ms: u64,
},
/// Show status of currently active watcher
Status,
/// Stop the currently running watcher
Stop,
}
/// Run a watch command
pub fn run(cmd: &WatchCmd, _conn: &mut Connection, _format: super::Format) -> Result<()> {
match cmd {
WatchCmd::Start { path, debounce_ms } => {
let mut marlin = libmarlin::Marlin::open_default()?;
let config = WatcherConfig {
debounce_ms: *debounce_ms,
..Default::default()
};
let canon_path = path.canonicalize().unwrap_or_else(|_| path.clone());
info!("Starting watcher for directory: {}", canon_path.display());
let mut watcher = marlin.watch(&canon_path, Some(config))?;
let status = watcher.status();
info!("Watcher started. Press Ctrl+C to stop watching.");
info!("Watching {} paths", status.watched_paths.len());
let start_time = Instant::now();
let mut last_status_time = Instant::now();
let running = Arc::new(AtomicBool::new(true));
let r_clone = running.clone();
ctrlc::set_handler(move || {
info!("Ctrl+C received. Signaling watcher to stop...");
r_clone.store(false, Ordering::SeqCst);
})?;
info!("Watcher run loop started. Waiting for Ctrl+C or stop signal...");
while running.load(Ordering::SeqCst) {
let current_status = watcher.status();
if current_status.state == WatcherState::Stopped {
info!("Watcher has stopped (detected by state). Exiting loop.");
break;
}
// Corrected line: removed the extra closing parenthesis
if last_status_time.elapsed() > Duration::from_secs(10) {
let uptime = start_time.elapsed();
info!(
"Watcher running for {}s, processed {} events, queue: {}, state: {:?}",
uptime.as_secs(),
current_status.events_processed,
current_status.queue_size,
current_status.state
);
last_status_time = Instant::now();
}
thread::sleep(Duration::from_millis(200));
}
info!("Watcher run loop ended. Explicitly stopping watcher instance...");
watcher.stop()?;
info!("Watcher instance fully stopped.");
Ok(())
}
WatchCmd::Status => {
info!("Status command: No active watcher process to query in this CLI invocation model.");
info!("To see live status, run 'marlin watch start' which prints periodic updates.");
Ok(())
}
WatchCmd::Stop => {
info!("Stop command: No active watcher process to stop in this CLI invocation model.");
info!("Please use Ctrl+C in the terminal where 'marlin watch start' is running.");
Ok(())
}
}
}

View File

@@ -154,6 +154,7 @@ fn main() -> Result<()> {
Commands::Annotate(a_cmd) => cli::annotate::run(&a_cmd, &mut conn, args.format)?,
Commands::Version(v_cmd) => cli::version::run(&v_cmd, &mut conn, args.format)?,
Commands::Event(e_cmd) => cli::event::run(&e_cmd, &mut conn, args.format)?,
Commands::Watch(watch_cmd) => cli::watch::run(&watch_cmd, &mut conn, args.format)?,
}
Ok(())