Crates.io | ccli |
lib.rs | ccli |
version | 0.0.1 |
source | src |
created_at | 2023-12-16 15:32:19.586561 |
updated_at | 2023-12-16 15:32:19.586561 |
description | Common command line interface |
homepage | https://github.com/clearloop/zink |
repository | https://github.com/clearloop/zink.git |
max_upload_size | |
id | 1071792 |
size | 3,484 |
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(())
}
}
GPL-3.0