Initial changes
This commit is contained in:
		
							parent
							
								
									6901f72977
								
							
						
					
					
						commit
						7d7db72a7b
					
				| 
						 | 
				
			
			@ -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(())
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -54,6 +54,22 @@ pub struct Config {
 | 
			
		|||
    sub_configs: Vec<Config>,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl Config {
 | 
			
		||||
    pub fn iter(self) -> ConfigIterator {
 | 
			
		||||
        return ConfigIterator::new(self.clone());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn get_task(&self, task_name: &String) -> Option<String> {
 | 
			
		||||
        for task in self.clone().tasks {
 | 
			
		||||
            if task.tag == *task_name {
 | 
			
		||||
                return Some(task.command)
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        None
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub struct ConfigIterator {
 | 
			
		||||
    stack: Vec<Config>
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -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<Config, String> {
 | 
			
		||||
    let config_file = read_config_file(path)?;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,2 +1,3 @@
 | 
			
		|||
pub mod file_resolvers;
 | 
			
		||||
pub mod config;
 | 
			
		||||
pub mod tasks;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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))
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
		Reference in New Issue