aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.ha5
-rw-r--r--hatask.ha27
2 files changed, 32 insertions, 0 deletions
diff --git a/config.ha b/config.ha
index a452665..b70341a 100644
--- a/config.ha
+++ b/config.ha
@@ -9,6 +9,7 @@ use io;
type config = struct {
tasksdir: str,
context: str,
+ tags: []str,
};
type cerror = !(fs::error | path::error | ini::error);
@@ -23,6 +24,7 @@ fn readconfig() (config | cerror) = {
const c = config {
tasksdir = strings::dup("tasks"),
context = strings::dup("*"),
+ tags = [],
};
for (const en => ini::next(&sc)?) {
switch (en.1) {
@@ -30,6 +32,8 @@ fn readconfig() (config | cerror) = {
c.tasksdir = strings::dup(strings::trim(en.2));
case "context" =>
c.tasksdir = strings::dup(strings::trim(en.2));
+ case "tags" =>
+ c.tags = strings::dupall(strings::split(strings::trim(en.2), ","));
case =>
void;
};
@@ -40,6 +44,7 @@ fn readconfig() (config | cerror) = {
fn cfinish(cfg: *config) void = {
free(cfg.tasksdir);
free(cfg.context);
+ strings::freeall(cfg.tags);
};
fn strcerror(e: cerror) str = {
diff --git a/hatask.ha b/hatask.ha
index 534a150..a5d9141 100644
--- a/hatask.ha
+++ b/hatask.ha
@@ -144,11 +144,35 @@ fn strrtaskerror(e: rtaskerror) str = {
};
};
+fn filtertags(cfg: config, tasks: *[]task) void = {
+ if (len(cfg.tags) == 0z) {
+ return;
+ };
+ for (let i = 0z; i < len(tasks); i += 1) {
+ const t = tasks[i];
+ let found = false;
+ for :tagloop (let tag .. t.tags) {
+ for (let tagfilter .. cfg.tags) {
+ if (tag == tagfilter) {
+ found = true;
+ break :tagloop;
+ };
+ };
+ };
+ if (!found) {
+ freetask(&tasks[i]);
+ delete(tasks[i]);
+ i -= 1;
+ };
+ };
+};
+
export fn main() void = {
const cmd = getopt::parse(os::args,
"tasklist",
('f', "path", "tasks directory"),
('c', "context", "context filter"),
+ ('t', "tags", "tags filter"),
('p', "sort by priority"),
("filter", ["filter tasks", "id"]: []getopt::help),
("f", ["filter tasks", "id"]: []getopt::help),
@@ -187,6 +211,8 @@ export fn main() void = {
cfg.tasksdir = strings::dup(opt.1);
case 'c' =>
cfg.context = strings::dup(opt.1);
+ case 't' =>
+ cfg.tags = strings::dupall(strings::split(opt.1, ","));
case 'p' =>
sortfn = &sortpriority;
case =>
@@ -202,6 +228,7 @@ export fn main() void = {
};
defer finishall(tasks);
sort::sort(tasks: []opaque, size(task), sortfn);
+ filtertags(cfg, &tasks);
const com: (str, *getopt::command) = match (cmd.subcmd) {
case void =>