Skip to main content

openlogi_cli/
lib.rs

1//! OpenLogi CLI implementation. The `openlogi` binary is a thin wrapper that
2//! calls [`run`]; the command tree and argument parsing live here.
3
4use anyhow::Result;
5use clap::Parser;
6use tracing_subscriber::{EnvFilter, fmt};
7
8mod cmd;
9
10/// OpenLogi: a local-first companion for Logitech HID++ peripherals.
11#[derive(Debug, Parser)]
12#[command(
13    name = "openlogi",
14    version,
15    about = "OpenLogi: a local-first companion for Logitech HID++ peripherals.",
16    long_about = None,
17)]
18struct Cli {
19    #[command(subcommand)]
20    cmd: Option<cmd::Command>,
21}
22
23/// Initialise logging, parse arguments, and dispatch the chosen subcommand.
24pub async fn run() -> Result<()> {
25    fmt()
26        .with_writer(std::io::stderr)
27        .with_env_filter(
28            EnvFilter::try_from_env("OPENLOGI_LOG").unwrap_or_else(|_| EnvFilter::new("info")),
29        )
30        .init();
31
32    let cli = Cli::parse();
33    let command = cli
34        .cmd
35        .unwrap_or(cmd::Command::List(cmd::list::ListArgs {}));
36    command.run().await
37}