aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd.ha19
-rw-r--r--hatask.ha2
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 = ["<name>"],
func = &filter,
},
command {
names = ["s", "show"],
- help = ["<id>"],
func = &show,
},
command {
names = ["w", "write"],
- help = ["<id>"],
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);