ccli

Crates.ioccli
lib.rsccli
version0.0.1
sourcesrc
created_at2023-12-16 15:32:19.586561
updated_at2023-12-16 15:32:19.586561
descriptionCommon command line interface
homepagehttps://github.com/clearloop/zink
repositoryhttps://github.com/clearloop/zink.git
max_upload_size
id1071792
size3,484
(clearloop)

documentation

https://docs.rs/ccli

README

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

Commit count: 36

cargo fmt