cron_when/cli/
start.rs

1use crate::cli::{actions::Action, commands, dispatch, telemetry};
2use anyhow::Result;
3
4/// Map verbosity count to tracing level
5const fn get_verbosity_level(verbose_count: u8) -> Option<tracing::Level> {
6    match verbose_count {
7        0 => None,
8        1 => Some(tracing::Level::INFO),
9        2 => Some(tracing::Level::DEBUG),
10        3 => Some(tracing::Level::TRACE),
11        _ => Some(tracing::Level::TRACE),
12    }
13}
14
15/// Main entry point for the CLI - builds and returns the Action
16pub fn start() -> Result<Action> {
17    // 1. Parse command-line arguments
18    let matches = commands::new().get_matches();
19
20    // 2. Extract verbosity level
21    let verbosity_level = get_verbosity_level(matches.get_count("verbose"));
22
23    // 3. Initialize telemetry
24    telemetry::init(verbosity_level)?;
25
26    // 4. Dispatch to appropriate action
27    let action = dispatch::handler(&matches)?;
28
29    // 5. Return the action for execution by the binary
30    Ok(action)
31}