diff options
| author | Julian Hurst <julian.hurst@digdash.com> | 2025-01-15 18:08:44 +0100 |
|---|---|---|
| committer | Julian Hurst <julian.hurst@digdash.com> | 2025-01-15 18:31:21 +0100 |
| commit | 0490236116c4fcf80563251e4175dbcc78e05787 (patch) | |
| tree | 4c702a8c0de8840984c3dd969da4827e3135476b /cmd.ha | |
| parent | 4129e3dba2cc3953af6b97fc1c99a1516b9214cd (diff) | |
| download | hatask-0490236116c4fcf80563251e4175dbcc78e05787.tar.gz | |
Add get command to get misc properties from tasks
Unknown entries in the task metadata are now added to a misc map and can be
gotten via the get command.
Diffstat (limited to 'cmd.ha')
| -rw-r--r-- | cmd.ha | 39 |
1 files changed, 39 insertions, 0 deletions
@@ -8,6 +8,7 @@ use os::exec; use strconv; use ascii; use format::tsv; +use map; type error = !(!str | io::error | path::error | exec::error | strconv::error); @@ -47,6 +48,10 @@ const commands: [_]command = [ names = ["t", "tsv"], func = &tsv, }, + command { + names = ["g", "get"], + func = &getmisc, + }, ]; fn execcommand(cfg: config, name: str, tasks: []task, args: arguments) (void | error) = { @@ -223,6 +228,40 @@ fn tsv(cfg: config, tasks: []task, a: arguments) (void | task | error) = { }; }; +fn getmisc(cfg: config, tasks: []task, a: arguments) (void | task | error) = { + const args = a.args; + if (len(args) == 0) { + for (let task .. tasks) { + const it = map::newiterator(task.misc); + for (let misc => map::next(&it)) { + fmt::printfln("{}: {}", misc.key, misc.val)!; + }; + }; + } else if (len(args) == 1) { + const id = strconv::stoz(a.args[0])?; + if (id >= len(tasks)) { + return "No such task"; + }; + const task = tasks[id]; + const it = map::newiterator(task.misc); + for (let misc => map::next(&it)) { + fmt::printfln("{}: {}", misc.key, misc.val)!; + }; + } else { + const id = strconv::stoz(args[0])?; + if (id >= len(tasks)) { + return "No such task"; + }; + const task = tasks[id]; + match (map::get(task.misc, args[1])) { + case void => + return "No such misc property"; + case let val: str => + fmt::printfln("{}: {}", args[1], val)!; + }; + }; +}; + fn listall(cfg: config, tasks: []task) void = { const headpad = PADDING - len("name") + len("priority"); const namepad = 10 - len("id") + len("name"); |
