diff --git a/src/cli.rs b/src/cli.rs index 097914d..252def9 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -5,8 +5,8 @@ use structopt::StructOpt; pub struct Cli { #[structopt(short = "f", long = "force")] - force: bool, + pub force: bool, //#[structopt(def)] - tasks: Vec, + pub tasks: Vec, } diff --git a/src/db.rs b/src/db.rs index 8fa8320..38fef27 100644 --- a/src/db.rs +++ b/src/db.rs @@ -7,6 +7,11 @@ use std::collections::HashMap; //use crate::log; use crate::dvcs; +#[derive(Debug)] +pub enum DbError { + TaskNotFound(String) +} + #[derive(Debug)] pub struct Entry { base_dir: PathBuf, @@ -109,6 +114,23 @@ impl Database { return res; } + // This one works with a list of tasks passed as argument + // It fails when a task wasn't found, instead of continuing silently + pub fn tasks_from(&self, list: Vec) -> Result, DbError> { + let mut res = Vec::new(); + for entry in &list { + let mut path = self.base_dir.clone(); + path.push(entry); + if !path.is_file() { + return Err(DbError::TaskNotFound(entry.to_string())); + } + if is_executable(&path) { + res.push(Task::new(self.base_dir.clone(), path.file_name().expect("WTF").to_os_string())); + } + } + return Ok(res); + } + pub fn task(&self, name: &str) -> Option { let mut path = self.base_dir.clone(); path.push(name); diff --git a/src/main.rs b/src/main.rs index 833bc8a..cadc91d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,11 +15,14 @@ fn main() { let db = db::Database::from_folder(&base_dir); let cmd = cli::Cli::from_args(); - println!("{:?}", cmd); - let truc = db.tasks(); + let tasks = if cmd.tasks.is_empty() { + db.tasks() + } else { + db.tasks_from(cmd.tasks).expect("Could not process the lsit of tasks given") + }; - for task in truc { + for task in tasks { let mut context = HashMap::new(); context.insert("$i18n_task", task.name.to_str().expect("WTF")); log::debug("found_task", Some(&context));