aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Hurst <ark@mansus.space>2024-11-15 01:59:36 +0100
committerJulian Hurst <ark@mansus.space>2024-11-15 02:14:03 +0100
commitec35f195dc2f0c41e4c8e4a9908aea51ea486c7d (patch)
tree156da756265da98e5d965d66d361e6cde2f706f3
parentb028ddf4d644f2cf8739dee4892dea79bbe43c1a (diff)
downloadhatask-ec35f195dc2f0c41e4c8e4a9908aea51ea486c7d.tar.gz
Add -c flag to filter context and fix context
Context now filters subtask folders as intended.
-rw-r--r--config.ha1
-rw-r--r--hatask.ha19
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();
};