added build vars
This commit is contained in:
parent
5da6b35ead
commit
864c7a7dac
@ -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<CuddleVariable>) {
|
||||
pub fn execute(self, variables: Vec<CuddleVariable>) -> anyhow::Result<()> {
|
||||
match self.script {
|
||||
CuddleScript::Shell(_s) => {
|
||||
CuddleScript::Shell(s) => {
|
||||
let mut arg_variables: Vec<CuddleVariable> = 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/");
|
||||
|
@ -68,8 +68,9 @@ pub fn extract_cuddle(config: CuddleConfig) -> anyhow::Result<Arc<Mutex<Vec<Cudd
|
||||
|
||||
if !cuddle_dest.exists() {
|
||||
pull_parent_cuddle_into_local(parent_plan, cuddle_dest.clone())?;
|
||||
recurse_parent(cuddle_dest, context.clone())?;
|
||||
}
|
||||
|
||||
recurse_parent(cuddle_dest, context.clone())?;
|
||||
}
|
||||
}
|
||||
|
||||
@ -77,7 +78,7 @@ pub fn extract_cuddle(config: CuddleConfig) -> anyhow::Result<Arc<Mutex<Vec<Cudd
|
||||
}
|
||||
|
||||
fn create_cuddle_local() -> anyhow::Result<PathBuf> {
|
||||
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<Mutex<Vec<CuddleContext>>>) -> 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());
|
||||
}
|
||||
}
|
||||
|
@ -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(())
|
||||
}
|
||||
|
@ -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<String>,
|
||||
pub args: Option<HashMap<String, CuddleShellScriptArg>>,
|
||||
}
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize)]
|
||||
pub struct CuddleDaggerScript {
|
||||
|
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user