xvc_pipeline/pipeline/
schema.rs1use std::{ffi::OsStr, path::Path};
2
3use crate::error::{Error, Result};
4use crate::pipeline::deps::XvcDependency;
5use crate::pipeline::XvcOutput;
6use serde::{Deserialize, Serialize};
7use strum_macros::{Display, EnumString, IntoStaticStr, VariantNames};
8use xvc_core::XvcPath;
9
10use super::XvcStepInvalidate;
11
12#[derive(Debug, Clone, Eq, PartialEq, EnumString, Display, IntoStaticStr, VariantNames)]
13#[strum(serialize_all = "lowercase")]
14pub enum XvcSchemaSerializationFormat {
15 Json,
16 Yaml,
17 }
20
21impl XvcSchemaSerializationFormat {
22 fn from_extension(ext: &OsStr) -> Result<Self> {
23 match ext.to_str().unwrap_or("") {
24 "json" | "JSON" => Ok(Self::Json),
25 "yaml" | "yml" => Ok(Self::Yaml),
26 _ => Err(Error::CannotInferFormatFromExtension {
28 extension: ext.into(),
29 }),
30 }
31 }
32
33 pub fn from_path(path: &Path) -> Result<Self> {
34 Self::from_extension(path.extension().unwrap_or_else(|| OsStr::new("")))
35 }
36}
37
38#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
41pub struct XvcPipelineSchema {
42 pub version: i32,
44 pub name: String,
48 pub workdir: XvcPath,
50 pub steps: Vec<XvcStepSchema>,
52}
53
54#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
57pub struct XvcStepSchema {
58 pub name: String,
60 pub command: String,
62 pub invalidate: XvcStepInvalidate,
64 pub dependencies: Vec<XvcDependency>,
67 pub outputs: Vec<XvcOutput>,
70}