added build vars
This commit is contained in:
parent
5da6b35ead
commit
864c7a7dac
@ -1,5 +1,5 @@
|
|||||||
use std::{
|
use std::{
|
||||||
env::current_dir,
|
env::{self, current_dir},
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
sync::{Arc, Mutex},
|
sync::{Arc, Mutex},
|
||||||
};
|
};
|
||||||
@ -11,7 +11,7 @@ use git2::Repository;
|
|||||||
use crate::{
|
use crate::{
|
||||||
actions,
|
actions,
|
||||||
context::{CuddleContext, CuddleTreeType},
|
context::{CuddleContext, CuddleTreeType},
|
||||||
model::CuddleScript,
|
model::{CuddleScript, CuddleShellScriptArg},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
@ -27,9 +27,28 @@ impl CuddleAction {
|
|||||||
Self { script, path, name }
|
Self { script, path, name }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn execute(self, variables: Vec<CuddleVariable>) {
|
pub fn execute(self, variables: Vec<CuddleVariable>) -> anyhow::Result<()> {
|
||||||
match self.script {
|
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(
|
match actions::shell::ShellAction::new(
|
||||||
self.name.clone(),
|
self.name.clone(),
|
||||||
format!(
|
format!(
|
||||||
@ -40,15 +59,16 @@ impl CuddleAction {
|
|||||||
self.name
|
self.name
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.execute(variables)
|
.execute(vars)
|
||||||
{
|
{
|
||||||
Ok(()) => {}
|
Ok(()) => Ok(()),
|
||||||
Err(e) => {
|
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))
|
self.variables.push(CuddleVariable::new(name, var))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let CuddleTreeType::Root = ctx.node_type {
|
if let CuddleTreeType::Root = ctx.node_type {
|
||||||
let mut temp_path = ctx.path.clone();
|
let mut temp_path = ctx.path.clone();
|
||||||
temp_path.push(".cuddle/tmp/");
|
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() {
|
if !cuddle_dest.exists() {
|
||||||
pull_parent_cuddle_into_local(parent_plan, cuddle_dest.clone())?;
|
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> {
|
fn create_cuddle_local() -> anyhow::Result<PathBuf> {
|
||||||
let mut curr_dir = current_dir()?;
|
let mut curr_dir = current_dir()?.clone();
|
||||||
curr_dir.push(".cuddle/");
|
curr_dir.push(".cuddle/");
|
||||||
|
|
||||||
if curr_dir.exists() {
|
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();
|
let mut cuddle_dest = destination_path.clone();
|
||||||
cuddle_dest.push("base");
|
cuddle_dest.push("base");
|
||||||
|
|
||||||
|
if !cuddle_dest.exists() {
|
||||||
pull_parent_cuddle_into_local(parent_plan, cuddle_dest.clone())?;
|
pull_parent_cuddle_into_local(parent_plan, cuddle_dest.clone())?;
|
||||||
|
}
|
||||||
return recurse_parent(cuddle_dest, context.clone());
|
return recurse_parent(cuddle_dest, context.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ use std::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use config::CuddleConfig;
|
use config::CuddleConfig;
|
||||||
|
use tracing::Level;
|
||||||
|
|
||||||
mod actions;
|
mod actions;
|
||||||
mod cli;
|
mod cli;
|
||||||
@ -23,6 +24,7 @@ fn main() -> anyhow::Result<()> {
|
|||||||
}
|
}
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
// Only build bare bones cli
|
// 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()?;
|
_ = cli::CuddleCli::new(Arc::new(Mutex::new(vec![])))?.execute()?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -31,7 +33,10 @@ fn main() -> anyhow::Result<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn init_logging() -> anyhow::Result<()> {
|
fn init_logging() -> anyhow::Result<()> {
|
||||||
tracing_subscriber::fmt().pretty().init();
|
tracing_subscriber::fmt()
|
||||||
|
.pretty()
|
||||||
|
.with_max_level(Level::INFO)
|
||||||
|
.init();
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -9,9 +9,22 @@ pub enum CuddleBase {
|
|||||||
String(String),
|
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)]
|
#[derive(Debug, Clone, PartialEq, Deserialize)]
|
||||||
pub struct CuddleShellScript {
|
pub struct CuddleShellScript {
|
||||||
pub description: Option<String>,
|
pub description: Option<String>,
|
||||||
|
pub args: Option<HashMap<String, CuddleShellScriptArg>>,
|
||||||
}
|
}
|
||||||
#[derive(Debug, Clone, PartialEq, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Deserialize)]
|
||||||
pub struct CuddleDaggerScript {
|
pub struct CuddleDaggerScript {
|
||||||
|
@ -63,6 +63,35 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"additionalProperties": false
|
"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