Target tasks from CLI
This commit is contained in:
parent
ca5e6c9e3d
commit
65ab08a75c
|
@ -5,8 +5,8 @@ use structopt::StructOpt;
|
|||
pub struct Cli {
|
||||
|
||||
#[structopt(short = "f", long = "force")]
|
||||
force: bool,
|
||||
pub force: bool,
|
||||
|
||||
//#[structopt(def)]
|
||||
tasks: Vec<String>,
|
||||
pub tasks: Vec<String>,
|
||||
}
|
||||
|
|
22
src/db.rs
22
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<String>) -> Result<Vec<Task>, 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<Task> {
|
||||
let mut path = self.base_dir.clone();
|
||||
path.push(name);
|
||||
|
|
|
@ -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));
|
||||
|
|
Loading…
Reference in New Issue