kasl/lib.rs
1//! # Kasl - Key Activity Synchronization and Logging
2//!
3//! A command-line utility for tracking work activities, managing tasks,
4//! and generating productivity reports.
5//!
6//! ## Usage
7//!
8//! ```rust,no_run
9//! use kasl::commands::Cli;
10//!
11//! #[tokio::main]
12//! async fn main() -> anyhow::Result<()> {
13//! Cli::menu().await
14//! }
15//! ```
16
17pub mod api;
18pub mod commands;
19pub mod db;
20pub mod libs;
21
22/// Runs the CLI: the shared entry point behind both the `kasl` and `ka` binaries.
23///
24/// Sets up tracing, handles the internal `--daemon-run` mode used when the
25/// watcher spawns itself, and otherwise dispatches the parsed command.
26///
27/// # Errors
28///
29/// Propagates whatever the executed command fails with.
30pub fn run() -> anyhow::Result<()> {
31 // Clear the binary a previous update left behind; it is only deletable
32 // once it is no longer the running image, which is now.
33 libs::update::Updater::sweep_backup();
34
35 let runtime = tokio::runtime::Runtime::new()?;
36 runtime.block_on(async {
37 // Initialize tracing only if debug mode is enabled; otherwise log output
38 // would clutter normal CLI usage.
39 if std::env::var("KASL_DEBUG").is_ok() || std::env::var("RUST_LOG").is_ok() {
40 tracing_subscriber::fmt()
41 .with_env_filter(tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or_else(|_| "kasl=debug".into()))
42 .init();
43 }
44
45 // Intercepted before clap: this flag is how the background monitoring
46 // process is launched, not part of the public command surface.
47 let args: Vec<String> = std::env::args().collect();
48 if args.len() > 1 && args[1] == "--daemon-run" {
49 commands::watch::run_as_daemon().await?;
50 } else {
51 // Non-blocking; only surfaces a notification when one is due.
52 libs::update::Updater::show_update_notification().await;
53
54 commands::Cli::menu().await?;
55 }
56
57 Ok(())
58 })
59}