|
|
@ -1,12 +1,14 @@
|
|
|
|
use std::path::PathBuf;
|
|
|
|
use std::path::PathBuf;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use embed_nu::IntoValue;
|
|
|
|
|
|
|
|
|
|
|
|
use crate::{distro::OSConfig, error::AppResult};
|
|
|
|
use crate::{distro::OSConfig, error::AppResult};
|
|
|
|
|
|
|
|
|
|
|
|
use super::{exec_builder::ExecBuilder, TaskTrait};
|
|
|
|
use super::{exec_builder::ExecBuilder, TaskTrait};
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
pub struct CustomTask {
|
|
|
|
pub struct CustomTask {
|
|
|
|
config_key: String,
|
|
|
|
config_key: Option<String>,
|
|
|
|
up_script: PathBuf,
|
|
|
|
up_script: PathBuf,
|
|
|
|
down_script: PathBuf,
|
|
|
|
down_script: PathBuf,
|
|
|
|
skip_on_false: bool,
|
|
|
|
skip_on_false: bool,
|
|
|
@ -14,7 +16,12 @@ pub struct CustomTask {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl CustomTask {
|
|
|
|
impl CustomTask {
|
|
|
|
pub fn new(name: String, config_key: String, skip_on_false: bool, order: usize) -> Self {
|
|
|
|
pub fn new(
|
|
|
|
|
|
|
|
name: String,
|
|
|
|
|
|
|
|
config_key: Option<String>,
|
|
|
|
|
|
|
|
skip_on_false: bool,
|
|
|
|
|
|
|
|
order: usize,
|
|
|
|
|
|
|
|
) -> Self {
|
|
|
|
let base_path = PathBuf::from(name);
|
|
|
|
let base_path = PathBuf::from(name);
|
|
|
|
Self {
|
|
|
|
Self {
|
|
|
|
config_key,
|
|
|
|
config_key,
|
|
|
@ -29,9 +36,13 @@ impl CustomTask {
|
|
|
|
impl TaskTrait for CustomTask {
|
|
|
|
impl TaskTrait for CustomTask {
|
|
|
|
#[tracing::instrument(level = "trace", skip_all)]
|
|
|
|
#[tracing::instrument(level = "trace", skip_all)]
|
|
|
|
fn up(&self, config: &OSConfig) -> AppResult<Option<ExecBuilder>> {
|
|
|
|
fn up(&self, config: &OSConfig) -> AppResult<Option<ExecBuilder>> {
|
|
|
|
let task_config = config.get_nu_value(&self.config_key)?;
|
|
|
|
let task_config = if let Some(key) = self.config_key.as_ref() {
|
|
|
|
|
|
|
|
config.get_nu_value(key)?
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
Option::<()>::None.into_value()
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
if self.skip_on_false && config_is_falsy(&task_config) {
|
|
|
|
if self.skip_on_false && self.config_key.is_some() && config_is_falsy(&task_config) {
|
|
|
|
Ok(None)
|
|
|
|
Ok(None)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
Ok(Some(ExecBuilder {
|
|
|
|
Ok(Some(ExecBuilder {
|
|
|
@ -44,9 +55,13 @@ impl TaskTrait for CustomTask {
|
|
|
|
|
|
|
|
|
|
|
|
#[tracing::instrument(level = "trace", skip_all)]
|
|
|
|
#[tracing::instrument(level = "trace", skip_all)]
|
|
|
|
fn down(&self, config: &OSConfig) -> AppResult<Option<ExecBuilder>> {
|
|
|
|
fn down(&self, config: &OSConfig) -> AppResult<Option<ExecBuilder>> {
|
|
|
|
let task_config = config.get_nu_value(&self.config_key)?;
|
|
|
|
let task_config = if let Some(key) = self.config_key.as_ref() {
|
|
|
|
|
|
|
|
config.get_nu_value(key)?
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
Option::<()>::None.into_value()
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
if self.skip_on_false && config_is_falsy(&task_config) {
|
|
|
|
if self.skip_on_false && self.config_key.is_some() && config_is_falsy(&task_config) {
|
|
|
|
Ok(None)
|
|
|
|
Ok(None)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
Ok(Some(ExecBuilder {
|
|
|
|
Ok(Some(ExecBuilder {
|
|
|
|