use clap::ValueEnum;
use std::{path::PathBuf, sync::LazyLock};
use strum::IntoEnumIterator;
use strum_macros::{EnumIter, EnumString, IntoStaticStr, VariantNames};
use crate::signature::Algorithm;
#[derive(
Debug,
Default,
ValueEnum,
EnumString,
VariantNames,
EnumIter,
Eq,
IntoStaticStr,
PartialEq,
PartialOrd,
Copy,
Clone,
)]
pub enum Verbosity {
None,
Errors,
Warnings,
#[default]
Info,
Debug,
Trace,
}
static VARIANTS_LIST: LazyLock<Vec<Verbosity>> = LazyLock::new(|| Verbosity::iter().collect());
impl Verbosity {
const fn index(self) -> usize {
self as usize
}
#[must_use]
pub fn up_max<S: Into<usize>>(self, steps: S) -> Self {
let new_index = self.index().saturating_add(steps.into()) % VARIANTS_LIST.len();
VARIANTS_LIST[new_index]
}
#[must_use]
pub fn down_max(self, steps: usize) -> Self {
let new_index = self.index().saturating_sub(steps);
VARIANTS_LIST[new_index]
}
}
impl From<bool> for Verbosity {
fn from(verbose: bool) -> Self {
if verbose { Self::Info } else { Self::Warnings }
}
}
#[derive(Debug, Default, ValueEnum, EnumString, VariantNames, IntoStaticStr, Clone, Copy)]
pub enum Overwrite {
#[default]
All,
None,
Main,
Alternative,
}
impl Overwrite {
#[must_use]
pub const fn main(&self) -> bool {
match self {
Self::All | Self::Main => true,
Self::None | Self::Alternative => false,
}
}
#[must_use]
pub const fn alt(&self) -> bool {
match self {
Self::All | Self::Alternative => true,
Self::None | Self::Main => false,
}
}
}
#[derive(Clone, Copy, Debug)]
pub enum FailOn {
AnyMissingValue,
Error,
}
impl From<bool> for FailOn {
fn from(verbose: bool) -> Self {
if verbose {
Self::AnyMissingValue
} else {
Self::Error
}
}
}
#[derive(Clone, Debug)]
pub enum ShowRetrieved {
No,
Primary(Option<PathBuf>),
All(Option<PathBuf>),
}
#[derive(Clone, Debug, Default)]
pub struct Settings {
pub verbosity: Verbosity,
pub assertion_loc: Option<PathBuf>,
pub sign_alg: Algorithm,
pub sign_key_loc: Option<PathBuf>,
pub cert_loc: Option<PathBuf>,
pub source_image_loc: Option<PathBuf>,
pub baked_loc: Option<PathBuf>,
}