Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
@@ -13,3 +13,4 @@ dotenv.workspace = true
|
||||
reqwest = { version = "0.12.2", features = ["json"]}
|
||||
serde = { version = "1.0.197", features = ["derive"] }
|
||||
serde_json = "1.0.115"
|
||||
tera = "1.19.1"
|
||||
|
@@ -1,4 +1,4 @@
|
||||
use std::path::PathBuf;
|
||||
use std::{collections::BTreeMap, path::PathBuf};
|
||||
|
||||
use anyhow::anyhow;
|
||||
use clap::{Parser, Subcommand};
|
||||
@@ -24,6 +24,9 @@ enum Commands {
|
||||
|
||||
#[arg(long = "drone-user", env = "DRONE_USER")]
|
||||
drone_user: String,
|
||||
|
||||
#[arg(long = "variable", short = 'v')]
|
||||
variables: Vec<String>,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -40,10 +43,16 @@ async fn main() -> anyhow::Result<()> {
|
||||
drone_token,
|
||||
drone_host,
|
||||
drone_user,
|
||||
variables,
|
||||
}) = cli.command
|
||||
{
|
||||
tracing::info!(template, drone_host, "executing drone upload");
|
||||
|
||||
let vars = variables
|
||||
.iter()
|
||||
.filter_map(|v| v.split_once('='))
|
||||
.collect::<BTreeMap<&str, &str>>();
|
||||
|
||||
let template_path = PathBuf::from(&template);
|
||||
if !template_path.exists() {
|
||||
anyhow::bail!("template: {} doesn't exist", template)
|
||||
@@ -59,6 +68,13 @@ async fn main() -> anyhow::Result<()> {
|
||||
.expect("filename to be utf8");
|
||||
let template_data = tokio::fs::read_to_string(&template_path).await?;
|
||||
|
||||
let mut ctx = tera::Context::new();
|
||||
for (name, val) in vars {
|
||||
tracing::debug!("adding value to template: ({}, {})", &name, &val);
|
||||
ctx.insert(name, val);
|
||||
}
|
||||
let template_data = tera::Tera::one_off(&template_data, &ctx, false)?;
|
||||
|
||||
let template_url = format!(
|
||||
"{}/api/templates/{}/{}",
|
||||
drone_host.trim_end_matches('/'),
|
||||
|
Reference in New Issue
Block a user