diff --git a/src/main.rs b/src/main.rs index 70c7177..403af78 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,8 +18,14 @@ fn main() -> Result<(), std::io::Error> { } else { task::from_dir_and_list(&base_dir, cmd.tasks).expect("Could not load given tasks") }; + + let (config_folder, ignored_tasks) = task::config(&std::path::Path::new(&base_dir)); for (task_name, task) in tasks.iter() { + if ignored_tasks.contains(&task_name) { + // Skip task which has CONFIG/task.ignore + continue; + } println!("TASK: {:?}", task_name); let mut context = HashMap::new(); diff --git a/src/task.rs b/src/task.rs index 66591a9..3614498 100644 --- a/src/task.rs +++ b/src/task.rs @@ -1,4 +1,4 @@ -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use std::ffi::OsString; use std::collections::HashMap; use std::process::Command; @@ -20,14 +20,26 @@ pub struct Task { pub cloned: bool, } -#[derive(Debug)] -pub struct Config { - HashMap, -} - -impl Config { - pub fn from_dir(basedir: &str) -> Config { - db::from(basedir, std::) +/// config returns an option of (settings directory, ignored tasks) as +/// (PathBuf, Vec) +pub fn config(basedir: &Path) -> (PathBuf, Vec) { + let hostname = std::env::var("HOST").unwrap_or_else( + |_| hostname::get().unwrap().into_string().unwrap() + ); + let path = basedir.join(hostname); + if path.is_dir() { + let ignored = path.read_dir().unwrap().filter_map(|x| { + if x.is_err() { return None; } + let mut name = x.unwrap().file_name().into_string().unwrap(); + if name.ends_with(".ignore") { + return Some(name.trim_end_matches(".ignore").to_string()); + } + return None; + }).collect(); + (path, ignored) + } else { + // TODO: load .ignore in default config? + (basedir.join("config"), Vec::new()) } }