adnv 1.5.0

CLI that tracks, checks and auto-updates infrastructure dependency versions across Terraform, Helm, Docker, Git and npm
Documentation
use std::path::PathBuf;

use super::Pipe;
use super::{Error, Result};
use serde::Deserialize;

/// Output a folder from actions pipe
#[derive(Debug, Deserialize)]
pub struct Action {
    path: PathBuf,
    /// if true or none, output directory will be dropped before the copy
    clean: Option<bool>,
}

impl Action {
    pub async fn execute(&self, pipe: &mut Pipe) -> Result<()> {
        super::validate_contained_path(&self.path, "output path")?;

        let input = pipe.input().ok_or(Error::NoInputInPipe)?;

        if self.path.exists() && self.clean.unwrap_or(true) {
            tokio::fs::remove_dir_all(&self.path).await.map_err(|e| {
                Error::CouldNotDeleteDirectory {
                    path: self.path.clone(),
                    err: e,
                }
            })?;
        }

        crate::util::fs::copy_dir(input.clone(), self.path.clone()).await
    }
}