diff --git a/src/build.rs b/src/build.rs index 2b198ee..6f28407 100644 --- a/src/build.rs +++ b/src/build.rs @@ -1,3 +1,6 @@ +use std::fmt; +use std::fmt::Display; + pub trait Runner { fn run(&self) -> Result<(), E>; } @@ -7,3 +10,12 @@ pub enum Env { Dev, Release, } + +impl Display for Env { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match self { + Env::Dev => write!(f, "dev"), + Env::Release => write!(f, "release"), + } + } +} diff --git a/src/main.rs b/src/main.rs index 109bfc8..36228ee 100644 --- a/src/main.rs +++ b/src/main.rs @@ -93,7 +93,7 @@ fn main() { if let Some(script_name) = script { let script_path = current_dir.join(script_name); - let script_runner = ScriptRunner::new(script_path); + let script_runner = ScriptRunner::new(script_path, &env); script_runner.run().expect("Post build runner failed"); } } @@ -108,7 +108,7 @@ fn main() { let post_build_runner = if let Some(script_name) = script { let script_path = current_dir.join(script_name); if script_path.exists() { - Some(ScriptRunner::new(script_path)) + Some(ScriptRunner::new(script_path, &env)) } else { eprintln!("Could not find script: {}", script_path.display()); None diff --git a/src/script_runner.rs b/src/script_runner.rs index e366fb3..0daf9f4 100644 --- a/src/script_runner.rs +++ b/src/script_runner.rs @@ -1,3 +1,4 @@ +use crate::build::Env; use crate::build::Runner; use crate::exec; use std::fmt; @@ -19,11 +20,15 @@ impl fmt::Display for Error { #[derive(Debug, Clone)] pub struct ScriptRunner { script_path: PathBuf, + env: Env, } impl ScriptRunner { - pub fn new(script_path: PathBuf) -> Self { - Self { script_path } + pub fn new(script_path: PathBuf, env: &Env) -> Self { + Self { + script_path, + env: env.clone(), + } } } @@ -32,7 +37,7 @@ impl Runner for ScriptRunner { exec::run(&exec::Config { work_dir: ".".into(), cmd: self.script_path.to_string_lossy().into(), - args: vec![], + args: vec![self.env.to_string()], }) .map_err(Error::Exec)?;