pub mod org; pub mod publish; pub mod watcher; use std::time::Duration; use std::{path::PathBuf, sync::mpsc}; use clap::Parser; use notify_debouncer_full::notify::{Event, RecursiveMode, Result, Watcher}; use notify_debouncer_full::{DebouncedEvent, new_debouncer}; use tracing::{error, info, level_filters::LevelFilter}; use tracing_subscriber::EnvFilter; #[derive(Debug, Parser)] #[command(name = "lumina", version, about)] struct Cli { #[arg(short = 'p', long)] path: Option, #[arg(short = 'v', long)] verbose: bool, } fn main() -> Result<()> { let args = Cli::parse(); let timer = tracing_subscriber::fmt::time::ChronoLocal::new("%Y-%m-%d_%I:%M:%S%.6f %P".to_owned()); let default_directive = if args.verbose { "organic=debug" } else { "organic=info" }; let filter = EnvFilter::builder() .with_default_directive(LevelFilter::WARN.into()) .parse_lossy(default_directive); tracing_subscriber::FmtSubscriber::builder() .with_env_filter(filter) // .with_line_number(true) .with_level(true) .with_target(false) .with_timer(timer) .init(); if let Some(path) = args.path { let (tx, rx) = mpsc::channel(); // Automatically select the best implementation for your platform. let mut watcher = new_debouncer(Duration::from_millis(500), None, tx).unwrap(); watcher.watch(&path, RecursiveMode::Recursive)?; loop { match rx.recv() { Ok(event) => event.map_or_else( |e| error!("Error: {:?}", e), |events| { for event in events { match watcher::watch(&event, &path) { Ok(()) => (), Err(e) => error!("internal error: {:?}", e), } } }, ), Err(e) => error!("watch error: {:?}", e), } } } else { info!("Nothing to do"); } Ok(()) }