use std::path::PathBuf;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum OpKind {
Create,
Mkdir,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct FileOp {
pub kind: OpKind,
pub path: PathBuf,
pub contents: String,
}
impl FileOp {
pub fn create(path: impl Into<PathBuf>, contents: impl Into<String>) -> Self {
Self {
kind: OpKind::Create,
path: path.into(),
contents: contents.into(),
}
}
pub fn mkdir(path: impl Into<PathBuf>) -> Self {
Self {
kind: OpKind::Mkdir,
path: path.into(),
contents: String::new(),
}
}
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct Plan {
pub ops: Vec<FileOp>,
}
impl Plan {
pub fn new() -> Self {
Self::default()
}
pub fn create(mut self, path: impl Into<PathBuf>, contents: impl Into<String>) -> Self {
self.ops.push(FileOp::create(path, contents));
self
}
pub fn mkdir(mut self, path: impl Into<PathBuf>) -> Self {
self.ops.push(FileOp::mkdir(path));
self
}
pub fn is_empty(&self) -> bool {
self.ops.is_empty()
}
}