From 373ed8172d62b84df70fee9c7f92658e203bb621 Mon Sep 17 00:00:00 2001 From: Julian Hurst Date: Fri, 15 Nov 2024 01:32:41 +0100 Subject: Add -a flag to add a task --- cmd.ha | 16 ++++++++++++++++ hatask.ha | 2 ++ 2 files changed, 18 insertions(+) diff --git a/cmd.ha b/cmd.ha index 4c85b0a..d22c70c 100644 --- a/cmd.ha +++ b/cmd.ha @@ -31,6 +31,10 @@ const commands: [_]command = [ names = ["s", "show"], func = &show, }, + command { + names = ["a", "add"], + func = &add, + }, command { names = ["w", "write"], func = &write, @@ -55,6 +59,18 @@ fn execcommand(cfg: config, name: str, tasks: []task, args: arguments) (void | e }; }; +fn add(cfg: config, tasks: []task, a: arguments) (void | task | error) = { + const args = a.args; + if (len(args) != 1z) { + getopt::printhelp(os::stderr, "write", a.help)?; + return; + }; + + let buf = path::init(cfg.tasksdir, args[0])?; + const c = exec::cmd("vim", path::string(&buf))?; + exec::exec(&c); +}; + fn write(cfg: config, tasks: []task, a: arguments) (void | task | error) = { const args = a.args; if (len(args) != 1z) { diff --git a/hatask.ha b/hatask.ha index 7807000..e7a1274 100644 --- a/hatask.ha +++ b/hatask.ha @@ -128,6 +128,8 @@ export fn main() void = { ("f", ["filter tasks", "id"]: []getopt::help), ("show", ["show task details", "id"]: []getopt::help), ("s", ["show task details", "id"]: []getopt::help), + ("add", ["add a task", "id"]: []getopt::help), + ("a", ["add a task", "id"]: []getopt::help), ("write", ["write a task", "id"]: []getopt::help), ("w", ["write a task", "id"]: []getopt::help), ("done", ["delete a task", "id"]: []getopt::help), -- cgit v1.2.3