diff options
Diffstat (limited to 'hatask.ha')
| -rw-r--r-- | hatask.ha | 38 |
1 files changed, 31 insertions, 7 deletions
@@ -11,9 +11,11 @@ use format::ini; use strconv; use encoding::utf8; use getopt; +use sort; type task = struct { name: str, + path: str, context: (str | void), tags: ([]str | void), priority: uint, @@ -88,12 +90,14 @@ fn readtask(taskpath: str) (task | rtaskerror) = { if (t.name == "") { t.name = strings::dup(path::basename(taskpath)); }; + t.path = strings::dup(taskpath); t.content = strings::dup(strings::trim(memio::string(&content)?)); return t; }; fn freetask(t: *task) void = { free(t.name); + free(t.path); free(t.content); if (t.context is str) { free(t.context as str); @@ -109,18 +113,24 @@ fn finishall(tasks: []task) void = { }; }; +fn sortname(a: const *opaque, b: const *opaque) int = { + const a = a: *task; + const b = b: *task; + return strings::compare(a.name, b.name); +}; + export fn main() void = { const cmd = getopt::parse(os::args, "tasklist", - "cmd", + ("filter", ["filter tasks", "id"]: []getopt::help), + ("f", ["filter tasks", "id"]: []getopt::help), + ("show", ["show task details", "id"]: []getopt::help), + ("s", ["show task details", "id"]: []getopt::help), + ("write", ["write a task", "id"]: []getopt::help), + ("w", ["write a task", "id"]: []getopt::help), ); defer getopt::finish(&cmd); - const com: []str = if (len(cmd.args) > 0) { - yield cmd.args; - } else { - yield ["filter"]; - }; const tasks = match (listtasks()) { case let e: fs::error => @@ -130,7 +140,21 @@ export fn main() void = { case let tasks: []task => yield tasks; }; + sort::sort(tasks: []opaque, size(task), &sortname); defer finishall(tasks); - execcommand(com[0], tasks, com[1..]...)!; + const com: (str, *getopt::command) = match (cmd.subcmd) { + case void => + listall(tasks); + return; + case let subcmd: (str, *getopt::command) => + yield (subcmd.0, subcmd.1); + }; + + match (execcommand(com.0, tasks, com.1)) { + case let e: error => + fmt::fatal(strerror(e)); + case => + void; + }; }; |
