use garde::Validate;
use serde::Deserialize;
use super::Config;
use super::validate::non_empty_hook_argv;
use super::validate_steps::inside_the_repo_str;
#[derive(Debug, Clone, Default, PartialEq, Eq, Deserialize, Validate)]
#[serde(deny_unknown_fields)]
#[garde(context(Config as config))]
#[garde(allow_unvalidated)]
#[non_exhaustive]
pub struct StepSpec {
pub task: Option<String>,
pub run: Option<Vec<String>>,
#[serde(default)]
#[garde(inner(custom(inside_the_repo_str)))]
pub writes: Vec<String>,
#[serde(default)]
#[garde(inner(custom(non_empty_hook_argv)))]
pub check: Option<Vec<String>>,
}
impl StepSpec {
#[must_use]
pub fn argv(&self) -> Vec<String> {
if let Some(task) = &self.task {
return vec![
"mise".to_owned(),
"run".to_owned(),
"--raw".to_owned(),
task.clone(),
];
}
self.run.clone().unwrap_or_default()
}
#[must_use]
pub fn command(&self) -> String {
self.argv().join(" ")
}
}
#[derive(Debug, Clone, Default, PartialEq, Eq, Deserialize)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct AttachPoints {
#[serde(default)]
pub version: Vec<String>,
#[serde(default)]
pub verify: Vec<String>,
#[serde(default)]
pub released: Vec<String>,
}
impl AttachPoints {
#[must_use]
pub fn is_empty(&self) -> bool {
self.version.is_empty() && self.verify.is_empty() && self.released.is_empty()
}
pub fn all_names(&self) -> impl Iterator<Item = &str> {
self.version
.iter()
.chain(&self.verify)
.chain(&self.released)
.map(String::as_str)
}
}
#[derive(Debug, Clone, Default, PartialEq, Eq, Deserialize)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct EcosystemSpec {
pub manifest: Option<String>,
pub lockfile: Option<String>,
pub artifact: Option<String>,
pub publish: Option<String>,
pub registry: Option<String>,
}
impl EcosystemSpec {
pub fn step_names(&self) -> impl Iterator<Item = &str> {
[
self.manifest.as_deref(),
self.lockfile.as_deref(),
self.artifact.as_deref(),
self.publish.as_deref(),
self.registry.as_deref(),
]
.into_iter()
.flatten()
}
}