pub(crate) mod cli;
pub(crate) mod command;
pub(crate) mod error;
pub(crate) mod telemetry;
use self::cli::Cli;
use crate::error::CliError;
use clap::Parser;
use std::process::ExitCode;
pub trait OnceCommand {
type Output;
type Error: std::error::Error;
fn execute(self) -> Result<Self::Output, Self::Error>;
}
pub trait OnceCommandWith {
type Output;
type Error: std::error::Error;
type Value: ?Sized;
fn execute_with(self, value: Self::Value) -> Result<Self::Output, Self::Error>;
}
const COMMAND_NAME: &str = env!("CARGO_BIN_NAME");
fn main() -> Result<ExitCode, CliError> {
let command_line = Cli::parse();
telemetry::init(command_line.max_level_filter())?;
command_line.execute()
}
impl<T, O, E, V> OnceCommand for T
where
E: std::error::Error,
V: Default,
T: OnceCommandWith<Output = O, Error = E, Value = V>,
{
type Output = O;
type Error = E;
fn execute(self) -> Result<Self::Output, Self::Error> {
Self::execute_with(self, V::default())
}
}