diff --git a/cuddle_cli/src/cli.rs b/cuddle_cli/src/cli.rs index 644c7b6..665acbf 100644 --- a/cuddle_cli/src/cli.rs +++ b/cuddle_cli/src/cli.rs @@ -1,5 +1,5 @@ use std::{ - env::current_dir, + env::{self, current_dir}, path::PathBuf, sync::{Arc, Mutex}, }; @@ -11,7 +11,7 @@ use git2::Repository; use crate::{ actions, context::{CuddleContext, CuddleTreeType}, - model::CuddleScript, + model::{CuddleScript, CuddleShellScriptArg}, }; #[derive(Debug, Clone)] @@ -27,9 +27,28 @@ impl CuddleAction { Self { script, path, name } } - pub fn execute(self, variables: Vec) { + pub fn execute(self, variables: Vec) -> anyhow::Result<()> { match self.script { - CuddleScript::Shell(_s) => { + CuddleScript::Shell(s) => { + let mut arg_variables: Vec = vec![]; + if let Some(args) = s.args { + for (k, v) in args { + let var = match v { + CuddleShellScriptArg::Env(e) => { + let env_var = env::var(e.key.clone())?; + CuddleVariable::new(k.clone(), env_var) + } + }; + + arg_variables.push(var); + } + } else { + arg_variables = vec![] + }; + + let mut vars = variables.clone(); + vars.append(&mut arg_variables); + match actions::shell::ShellAction::new( self.name.clone(), format!( @@ -40,15 +59,16 @@ impl CuddleAction { self.name ), ) - .execute(variables) + .execute(vars) { - Ok(()) => {} + Ok(()) => Ok(()), Err(e) => { - log::error!("{}", e) + log::error!("{}", e); + Err(e) } } } - CuddleScript::Dagger(_d) => {} + CuddleScript::Dagger(_d) => Err(anyhow::anyhow!("not implemented yet!")), } } } @@ -132,6 +152,7 @@ impl<'a> CuddleCli<'a> { self.variables.push(CuddleVariable::new(name, var)) } } + if let CuddleTreeType::Root = ctx.node_type { let mut temp_path = ctx.path.clone(); temp_path.push(".cuddle/tmp/"); diff --git a/cuddle_cli/src/context.rs b/cuddle_cli/src/context.rs index 11be2b3..8472a3b 100644 --- a/cuddle_cli/src/context.rs +++ b/cuddle_cli/src/context.rs @@ -68,8 +68,9 @@ pub fn extract_cuddle(config: CuddleConfig) -> anyhow::Result anyhow::Result anyhow::Result { - let mut curr_dir = current_dir()?; + let mut curr_dir = current_dir()?.clone(); curr_dir.push(".cuddle/"); if curr_dir.exists() { @@ -160,7 +161,9 @@ fn recurse_parent(path: PathBuf, context: Arc>>) -> any let mut cuddle_dest = destination_path.clone(); cuddle_dest.push("base"); - pull_parent_cuddle_into_local(parent_plan, cuddle_dest.clone())?; + if !cuddle_dest.exists() { + pull_parent_cuddle_into_local(parent_plan, cuddle_dest.clone())?; + } return recurse_parent(cuddle_dest, context.clone()); } } diff --git a/cuddle_cli/src/main.rs b/cuddle_cli/src/main.rs index 6f0d9ef..f6e2699 100644 --- a/cuddle_cli/src/main.rs +++ b/cuddle_cli/src/main.rs @@ -4,6 +4,7 @@ use std::{ }; use config::CuddleConfig; +use tracing::Level; mod actions; mod cli; @@ -23,6 +24,7 @@ fn main() -> anyhow::Result<()> { } Err(_) => { // Only build bare bones cli + log::info!("was not opened in a repo with git, only showing bare-bones options"); _ = cli::CuddleCli::new(Arc::new(Mutex::new(vec![])))?.execute()?; } } @@ -31,7 +33,10 @@ fn main() -> anyhow::Result<()> { } fn init_logging() -> anyhow::Result<()> { - tracing_subscriber::fmt().pretty().init(); + tracing_subscriber::fmt() + .pretty() + .with_max_level(Level::INFO) + .init(); Ok(()) } diff --git a/cuddle_cli/src/model.rs b/cuddle_cli/src/model.rs index 49c7fa0..d870c70 100644 --- a/cuddle_cli/src/model.rs +++ b/cuddle_cli/src/model.rs @@ -9,9 +9,22 @@ pub enum CuddleBase { String(String), } +#[derive(Debug, Clone, PartialEq, Deserialize)] +pub struct CuddleShellScriptArgEnv { + pub key: String, +} + +#[derive(Debug, Clone, PartialEq, Deserialize)] +#[serde(tag = "type")] +pub enum CuddleShellScriptArg { + #[serde(alias = "env")] + Env(CuddleShellScriptArgEnv), +} + #[derive(Debug, Clone, PartialEq, Deserialize)] pub struct CuddleShellScript { pub description: Option, + pub args: Option>, } #[derive(Debug, Clone, PartialEq, Deserialize)] pub struct CuddleDaggerScript { diff --git a/schemas/base.json b/schemas/base.json index b865d2f..cd6ac55 100644 --- a/schemas/base.json +++ b/schemas/base.json @@ -63,6 +63,35 @@ } }, "additionalProperties": false + }, + "args": { + "title": "arguments to send to the specified script", + "type": "object", + "patternProperties": { + "^.*$": { + "anyOf": [ + { + "type": "object", + "required": [ + "type", + "key" + ], + "additionalProperties": false, + "properties": { + "type": { + "enum": [ + "env" + ] + }, + "key": { + "title": "the environment key to pull arg from", + "type": "string" + } + } + } + ] + } + } } } }