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        _ => Some(tracing::Level::TRACE),
11    }
12}
13
14/// Main entry point for the CLI - builds and returns the Action
15///
16/// # Errors
17///
18/// Returns an error if argument parsing, telemetry initialization, or action dispatch fails
19pub fn start() -> Result<Action> {
20    // 1. Parse command-line arguments
21    let matches = commands::new().get_matches();
22
23    // 2. Extract verbosity level
24    let verbosity_level = get_verbosity_level(matches.get_count("verbose"));
25
26    // 3. Initialize telemetry
27    telemetry::init(verbosity_level)?;
28
29    // 4. Dispatch to appropriate action
30    let action = dispatch::handler(&matches)?;
31
32    // 5. Return the action for execution by the binary
33    Ok(action)
34}