From e2b4bcd44149125b5e2a53579e1340ec10bc8eb3 Mon Sep 17 00:00:00 2001 From: Julian Hurst Date: Fri, 15 Nov 2024 01:14:07 +0100 Subject: Remove useless field and add done command --- cmd.ha | 19 +++++++++++++++---- hatask.ha | 2 ++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/cmd.ha b/cmd.ha index dd267b3..dd4afc1 100644 --- a/cmd.ha +++ b/cmd.ha @@ -14,7 +14,6 @@ type func = fn(tasks: []task, args: arguments) (void | task | error); type command = struct { names: []str, - help: []getopt::help, func: *func, }; @@ -25,19 +24,20 @@ const PADDING: size = 30z; const commands: [_]command = [ command { names = ["f", "filter"], - help = [""], func = &filter, }, command { names = ["s", "show"], - help = [""], func = &show, }, command { names = ["w", "write"], - help = [""], func = &write, }, + command { + names = ["d", "done"], + func = &do, + }, ]; fn execcommand(name: str, tasks: []task, args: arguments) (void | error) = { @@ -100,6 +100,17 @@ fn printtask(t: task, id: size) (void | error) = { )!; }; +fn do(tasks: []task, a: arguments) (void | task | error) = { + if (len(a.args) != 1z) { + getopt::printhelp(os::stderr, "done", a.help)?; + os::exit(os::status::FAILURE); + }; + const id = strconv::stoz(a.args[0])?; + const t = tasks[id]; + os::remove(t.path)?; + fmt::printfln("Task {}: \"{}\" done (deleted)", id, t.name)!; +}; + fn filter(tasks: []task, a: arguments) (void | task | error) = { const headpad = PADDING - len("name") + len("priority"); const namepad = 10 - len("id") + len("name"); diff --git a/hatask.ha b/hatask.ha index c15f2a0..33aeb2e 100644 --- a/hatask.ha +++ b/hatask.ha @@ -128,6 +128,8 @@ export fn main() void = { ("s", ["show task details", "id"]: []getopt::help), ("write", ["write a task", "id"]: []getopt::help), ("w", ["write a task", "id"]: []getopt::help), + ("done", ["delete a task", "id"]: []getopt::help), + ("d", ["delete a task", "id"]: []getopt::help), ); defer getopt::finish(&cmd); -- cgit v1.2.3