1 unstable release

0.0.1 Dec 16, 2023

#21 in #verbose

Download history 11/week @ 2023-12-30 1/week @ 2024-01-27 9/week @ 2024-02-17 16/week @ 2024-02-24 2/week @ 2024-03-02 2/week @ 2024-03-09 14/week @ 2024-03-23 42/week @ 2024-03-30 5/week @ 2024-04-06 2/week @ 2024-04-13

63 downloads per month
Used in 4 crates

GPL-3.0-only

4KB

ccli

Common command line interface.

//! Common command line interface.

use anyhow::Error;
pub use clap::{self, Parser};
pub use color_eyre::{eyre::eyre, Result};
use tracing_subscriber::filter::EnvFilter;

/// Shared application interface.
pub trait App: Parser {
    /// Verbose logging level.
    fn verbose(&self) -> u8;

    /// Run application.
    fn run(&self) -> anyhow::Result<()>;

    /// Start application.
    fn start() -> Result<()> {
        color_eyre::install()?;

        let app = Self::parse();
        let name = Self::command().get_name().to_string();
        let env =
            EnvFilter::try_from_default_env().unwrap_or(EnvFilter::new(match app.verbose() {
                0 => format!("{name}=info"),
                1 => format!("{name}=debug"),
                2 => "debug".into(),
                _ => "trace".into(),
            }));

        tracing_subscriber::fmt().with_env_filter(env).init();
        app.run().map_err(|e| eyre!("Failed to run app, {e}"))?;
        Ok(())
    }
}

LICENSE

GPL-3.0

Dependencies

~9–12MB
~201K SLoC