From 7d7db72a7b63f83b4239d2c98413a7aa13b48951 Mon Sep 17 00:00:00 2001 From: Ian Wijma Date: Wed, 3 Apr 2024 21:29:38 +1100 Subject: [PATCH] Initial changes --- src/commands/run.rs | 13 +++++++++++++ src/utils/config.rs | 22 ++++++++++++++++------ src/utils/mod.rs | 1 + src/utils/tasks.rs | 9 +++++++++ 4 files changed, 39 insertions(+), 6 deletions(-) create mode 100644 src/utils/tasks.rs diff --git a/src/commands/run.rs b/src/commands/run.rs index 78139af..f4a2148 100644 --- a/src/commands/run.rs +++ b/src/commands/run.rs @@ -1,6 +1,7 @@ use clap::Args; use crate::utils::config::{parse_config, validate_config}; use crate::utils::file_resolvers::resolve_configuration_file; +use crate::utils::tasks::run_task; #[derive(Args, Debug)] pub struct Arguments { @@ -22,6 +23,18 @@ pub fn run (arguments: &Arguments) -> Result<(), String> { Err(err) => return Err(err) } + for config in config.clone().iter() { + match config.get_task(command) { + None => {} + Some(task) => { + match run_task(&task) { + Ok(_) => {} + Err(err) => return Err(err) + } + } + } + } + println!("{:?}", config); Ok(()) diff --git a/src/utils/config.rs b/src/utils/config.rs index bd27236..7e2c0f2 100644 --- a/src/utils/config.rs +++ b/src/utils/config.rs @@ -54,6 +54,22 @@ pub struct Config { sub_configs: Vec, } +impl Config { + pub fn iter(self) -> ConfigIterator { + return ConfigIterator::new(self.clone()); + } + + pub fn get_task(&self, task_name: &String) -> Option { + for task in self.clone().tasks { + if task.tag == *task_name { + return Some(task.command) + } + } + + None + } +} + pub struct ConfigIterator { stack: Vec } @@ -77,12 +93,6 @@ impl Iterator for ConfigIterator { } } -impl Config { - fn iter(self) -> ConfigIterator { - return ConfigIterator::new(self.clone()); - } -} - pub fn parse_config(path: &PathBuf) -> Result { let config_file = read_config_file(path)?; diff --git a/src/utils/mod.rs b/src/utils/mod.rs index a5592b5..2d566c5 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -1,2 +1,3 @@ pub mod file_resolvers; pub mod config; +pub mod tasks; diff --git a/src/utils/tasks.rs b/src/utils/tasks.rs new file mode 100644 index 0000000..de58d95 --- /dev/null +++ b/src/utils/tasks.rs @@ -0,0 +1,9 @@ +use std::process::Command; + +pub fn run_task(task: &String) -> Result<(), String> { + let mut command = Command::new(task); + match command.spawn().unwrap().wait() { + Ok(_) => Ok(()), + Err(_) => Err(format!("Task failed: {}", task)) + } +} \ No newline at end of file