Add finalising commands for things like git
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
use crate::manifest::{FileDefinition, Manifest, Source, Transform, Params};
|
use crate::manifest::{FileDefinition, Manifest, Params, Source, Transform};
|
||||||
use eyre::Result;
|
use eyre::{Result, ensure};
|
||||||
use tracing::instrument;
|
use tracing::instrument;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@@ -17,7 +17,9 @@ impl Context {
|
|||||||
let params = Params::load_user()?.merge(params);
|
let params = Params::load_user()?.merge(params);
|
||||||
Ok(Context {
|
Ok(Context {
|
||||||
manifest: load_manifest(&source)?,
|
manifest: load_manifest(&source)?,
|
||||||
root: source.parent().ok_or_else(|| eyre::eyre!("Expect manifest to have a parent"))?,
|
root: source
|
||||||
|
.parent()
|
||||||
|
.ok_or_else(|| eyre::eyre!("Expect manifest to have a parent"))?,
|
||||||
params,
|
params,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -30,12 +32,25 @@ impl Context {
|
|||||||
self.generate_file(&dest, path, def)?;
|
self.generate_file(&dest, path, def)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for command in &self.manifest.commands {
|
||||||
|
let success = std::process::Command::new(&command.command)
|
||||||
|
.args(&command.args)
|
||||||
|
.current_dir(&dest)
|
||||||
|
.status()?
|
||||||
|
.success();
|
||||||
|
ensure!(success, "Command {:?} failed", command.command);
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument]
|
#[instrument]
|
||||||
fn generate_file(&self, dest: &Path, path: &PathBuf, def: &FileDefinition) -> Result<()> {
|
fn generate_file(&self, dest: &Path, path: &PathBuf, def: &FileDefinition) -> Result<()> {
|
||||||
std::fs::create_dir_all(dest.join(path).parent().expect("`dest` should be an absolute path with a parent"))?;
|
std::fs::create_dir_all(
|
||||||
|
dest.join(path)
|
||||||
|
.parent()
|
||||||
|
.expect("`dest` should be an absolute path with a parent"),
|
||||||
|
)?;
|
||||||
let mut input = self
|
let mut input = self
|
||||||
.root
|
.root
|
||||||
.join(
|
.join(
|
||||||
@@ -67,13 +82,8 @@ fn load_manifest(src: &Source) -> Result<Manifest> {
|
|||||||
Ok(toml::from_str(std::str::from_utf8(&src.load()?)?)?)
|
Ok(toml::from_str(std::str::from_utf8(&src.load()?)?)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[instrument(skip(input))]
|
#[instrument(skip(input))]
|
||||||
fn run_template(
|
fn run_template(args: &Params, params: &Params, input: Vec<u8>) -> Result<Vec<u8>> {
|
||||||
args: &Params,
|
|
||||||
params: &Params,
|
|
||||||
input: Vec<u8>,
|
|
||||||
) -> Result<Vec<u8>> {
|
|
||||||
let engine = upon::Engine::new();
|
let engine = upon::Engine::new();
|
||||||
let context = args.clone().merge(params.clone());
|
let context = args.clone().merge(params.clone());
|
||||||
Ok(engine
|
Ok(engine
|
||||||
|
|||||||
@@ -3,10 +3,18 @@ use serde::{Deserialize, Serialize};
|
|||||||
use std::{collections::HashMap, convert::Infallible, path::PathBuf, str::FromStr};
|
use std::{collections::HashMap, convert::Infallible, path::PathBuf, str::FromStr};
|
||||||
use tracing::instrument;
|
use tracing::instrument;
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Deserialize, Default)]
|
||||||
|
#[serde(default)]
|
||||||
pub struct Manifest {
|
pub struct Manifest {
|
||||||
pub parameters: HashMap<String, ParameterDefinition>,
|
pub parameters: HashMap<String, ParameterDefinition>,
|
||||||
pub files: HashMap<PathBuf, FileDefinition>,
|
pub files: HashMap<PathBuf, FileDefinition>,
|
||||||
|
pub commands: Vec<Command>
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Deserialize)]
|
||||||
|
pub struct Command {
|
||||||
|
pub command: String,
|
||||||
|
pub args: Vec<String>
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Deserialize)]
|
||||||
|
|||||||
Reference in New Issue
Block a user