Add finalising commands for things like git
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use crate::manifest::{FileDefinition, Manifest, Source, Transform, Params};
|
||||
use eyre::Result;
|
||||
use crate::manifest::{FileDefinition, Manifest, Params, Source, Transform};
|
||||
use eyre::{Result, ensure};
|
||||
use tracing::instrument;
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -17,7 +17,9 @@ impl Context {
|
||||
let params = Params::load_user()?.merge(params);
|
||||
Ok(Context {
|
||||
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,
|
||||
})
|
||||
}
|
||||
@@ -30,12 +32,25 @@ impl Context {
|
||||
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(())
|
||||
}
|
||||
|
||||
#[instrument]
|
||||
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
|
||||
.root
|
||||
.join(
|
||||
@@ -67,13 +82,8 @@ fn load_manifest(src: &Source) -> Result<Manifest> {
|
||||
Ok(toml::from_str(std::str::from_utf8(&src.load()?)?)?)
|
||||
}
|
||||
|
||||
|
||||
#[instrument(skip(input))]
|
||||
fn run_template(
|
||||
args: &Params,
|
||||
params: &Params,
|
||||
input: Vec<u8>,
|
||||
) -> Result<Vec<u8>> {
|
||||
fn run_template(args: &Params, params: &Params, input: Vec<u8>) -> Result<Vec<u8>> {
|
||||
let engine = upon::Engine::new();
|
||||
let context = args.clone().merge(params.clone());
|
||||
Ok(engine
|
||||
|
||||
@@ -3,10 +3,18 @@ use serde::{Deserialize, Serialize};
|
||||
use std::{collections::HashMap, convert::Infallible, path::PathBuf, str::FromStr};
|
||||
use tracing::instrument;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize)]
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Default)]
|
||||
#[serde(default)]
|
||||
pub struct Manifest {
|
||||
pub parameters: HashMap<String, ParameterDefinition>,
|
||||
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)]
|
||||
|
||||
Reference in New Issue
Block a user