feat: with schema
Some checks failed
continuous-integration/drone/push Build is failing

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
2023-07-02 00:47:14 +02:00
parent 6a82e0c10a
commit 12bd424f18
8 changed files with 164 additions and 23 deletions

View File

@@ -1,5 +1,7 @@
use std::path::PathBuf;
use clap::ArgMatches;
use crate::{
actions::shell::ShellAction,
model::{CuddleScript, CuddleShellScriptArg, CuddleVariable},
@@ -12,15 +14,30 @@ pub mod shell;
pub struct CuddleAction {
pub script: CuddleScript,
pub path: PathBuf,
pub description: Option<String>,
pub name: String,
}
#[allow(dead_code)]
impl CuddleAction {
pub fn new(script: CuddleScript, path: PathBuf, name: String) -> Self {
Self { script, path, name }
pub fn new(
script: CuddleScript,
path: PathBuf,
name: String,
description: Option<String>,
) -> Self {
Self {
script,
path,
name,
description,
}
}
pub fn execute(self, variables: Vec<CuddleVariable>) -> anyhow::Result<()> {
pub fn execute(
self,
matches: &ArgMatches,
variables: Vec<CuddleVariable>,
) -> anyhow::Result<()> {
match self.script {
CuddleScript::Shell(s) => {
let mut arg_variables: Vec<CuddleVariable> = vec![];
@@ -28,15 +45,18 @@ impl CuddleAction {
for (k, v) in args {
let var = match v {
CuddleShellScriptArg::Env(e) => {
let env_var = match std::env::var(e.key.clone()) {
Ok(var) => var,
Err(e) => {
log::error!("env_variable not found: {}", k);
return Err(anyhow::anyhow!(e));
}
};
let env_var = matches.get_one::<String>(&e.key).cloned().unwrap();
CuddleVariable::new(k.clone(), env_var)
}
CuddleShellScriptArg::Flag(flag) => {
match matches.get_one::<String>(&flag.name) {
Some(flag_var) => {
CuddleVariable::new(k.clone(), flag_var.clone())
}
None => continue,
}
}
};
arg_variables.push(var);