pegase 0.2.0

Cli to generate secret config files from yaml recipe
Documentation
use std::{collections::BTreeMap, fmt::Display, path::Path};

use garde::Validate;
use itertools::Itertools;

use crate::internal::sops::{self, SopsCreationRule, SopsFormat};

pub fn all_unique(s: &str, _: &()) -> garde::Result {
    if s.chars().all_unique() {
        Ok(())
    } else {
        Err(garde::Error::new("must not contain duplicate characters"))
    }
}

pub fn is_file_path(path: &Path, _: &()) -> garde::Result {
    // TODO: add !has_trailing_sep check when stable
    if path.file_name().is_some() {
        Ok(())
    } else {
        Err(garde::Error::new("must be a file path"))
    }
}

pub fn dive_vec<T>(v: &[T], _: &()) -> garde::Result
where
    T: Validate,
    <T as Validate>::Context: Default,
{
    for item in v {
        item.validate().map_err(garde::Error::new)?;
    }

    Ok(())
}

pub fn dive_btreemap_values<K, T>(v: &BTreeMap<K, T>, _: &()) -> garde::Result
where
    K: Display,
    T: Validate,
    <T as Validate>::Context: Default,
{
    for value in v.values() {
        value.validate().map_err(garde::Error::new)?;
    }

    Ok(())
}

pub fn is_sops_args_valid(config: &SopsCreationRule, _: &()) -> garde::Result {
    if config.enable {
        sops::encrypt(
            Path::new("test"),
            "test".to_string(),
            config,
            SopsFormat::Binary,
        )
        .map_err(garde::Error::new)?;
    }

    Ok(())
}