diff options
Diffstat (limited to 'hatask.ha')
| -rw-r--r-- | hatask.ha | 19 |
1 files changed, 12 insertions, 7 deletions
@@ -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(); }; |
