Load host config (not passed to task yet) and respect ignored tasks

This commit is contained in:
southerntofu 2020-11-25 17:10:14 +01:00
parent 02e6a5d827
commit e9bc8434a5
2 changed files with 27 additions and 9 deletions

View File

@ -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();

View File

@ -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<String, String>,
}
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<String>)
pub fn config(basedir: &Path) -> (PathBuf, Vec<String>) {
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())
}
}