From ec35f195dc2f0c41e4c8e4a9908aea51ea486c7d Mon Sep 17 00:00:00 2001 From: Julian Hurst Date: Fri, 15 Nov 2024 01:59:36 +0100 Subject: Add -c flag to filter context and fix context Context now filters subtask folders as intended. --- config.ha | 1 + hatask.ha | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/config.ha b/config.ha index e465294..4936492 100644 --- a/config.ha +++ b/config.ha @@ -1,3 +1,4 @@ type config = struct { tasksdir: str, + context: str, }; diff --git a/hatask.ha b/hatask.ha index df8cf6d..c92f688 100644 --- a/hatask.ha +++ b/hatask.ha @@ -12,6 +12,7 @@ use strconv; use encoding::utf8; use getopt; use sort; +use fnmatch; type task = struct { name: str, @@ -32,17 +33,17 @@ fn listtasks(root: str = "tasks", context: str = "*") ([]task | rtaskerror) = { defer fs::dirents_free(dirents); let tasks: []task = []; for (const dirent .. dirents) { - if (context == "*" || dirent.name == context) { - if (fs::isdir(dirent.ftype)) { + if (fs::isdir(dirent.ftype)) { + if (context == "*" || fnmatch::fnmatch(context, dirent.name)) { let buf = path::init()?; const p = path::push(&buf, root, dirent.name)?; append(tasks, listtasks(p)?...); - } else { - let buf = path::init()?; - const p = path::push(&buf, root, dirent.name)?; - let t = readtask(p)?; - append(tasks, t); }; + } else { + let buf = path::init()?; + const p = path::push(&buf, root, dirent.name)?; + let t = readtask(p)?; + append(tasks, t); }; }; return tasks; @@ -140,6 +141,7 @@ export fn main() void = { const cmd = getopt::parse(os::args, "tasklist", ('f', "path", "tasks directory"), + ('c', "context", "context filter"), ("filter", ["filter tasks", "id"]: []getopt::help), ("f", ["filter tasks", "id"]: []getopt::help), ("show", ["show task details", "id"]: []getopt::help), @@ -157,11 +159,14 @@ export fn main() void = { const cfg: config = config { tasksdir = "tasks", + context = "*", }; for (let opt .. cmd.opts) { switch (opt.0) { case 'f' => cfg.tasksdir = opt.1; + case 'c' => + cfg.context = opt.1; case => abort(); }; -- cgit v1.2.3