use clap::{Parser, ValueEnum};
use std::{
fmt::{self, Display},
process::{ExitCode, Termination},
};
mod command;
pub use command::*;
mod utils;
pub use utils::*;
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)] pub struct Cli {
#[command(subcommand)]
pub command: Commands,
#[arg(
global = true,
short = 'f',
long = "error-format",
env = "CEDAR_ERROR_FORMAT",
default_value_t,
value_enum
)]
pub err_fmt: ErrorFormat,
}
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, ValueEnum)]
pub enum ErrorFormat {
#[default]
Human,
Plain,
Json,
}
impl Display for ErrorFormat {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"{}",
match self {
ErrorFormat::Human => "human",
ErrorFormat::Plain => "plain",
ErrorFormat::Json => "json",
}
)
}
}
#[derive(Eq, PartialEq, Debug, Copy, Clone)]
pub enum CedarExitCode {
Success,
Failure,
AuthorizeDeny,
ValidationFailure,
#[cfg(any(feature = "partial-eval", feature = "tpe"))]
Unknown,
}
impl Termination for CedarExitCode {
fn report(self) -> ExitCode {
match self {
CedarExitCode::Success => ExitCode::SUCCESS,
CedarExitCode::Failure => ExitCode::FAILURE,
CedarExitCode::AuthorizeDeny => ExitCode::from(2),
CedarExitCode::ValidationFailure => ExitCode::from(3),
#[cfg(any(feature = "partial-eval", feature = "tpe"))]
CedarExitCode::Unknown => ExitCode::SUCCESS,
}
}
}