diff options
| author | Julian Hurst <ark@mansus.space> | 2024-11-15 01:32:41 +0100 |
|---|---|---|
| committer | Julian Hurst <ark@mansus.space> | 2024-11-15 01:45:27 +0100 |
| commit | 86ef1210a686bce0db3ead2760bf4d401e23883a (patch) | |
| tree | 5782556e504ac95c7bc6b49241a53a0713443a7e /cmd.ha | |
| parent | d8e2f1042367e19cb10e00a2004960fe1a40582c (diff) | |
| download | hatask-86ef1210a686bce0db3ead2760bf4d401e23883a.tar.gz | |
Create config struct and pass to commands
Diffstat (limited to 'cmd.ha')
| -rw-r--r-- | cmd.ha | 18 |
1 files changed, 9 insertions, 9 deletions
@@ -11,7 +11,7 @@ use format::tsv; type error = !(!str | io::error | path::error | exec::error | strconv::error); -type func = fn(tasks: []task, args: arguments) (void | task | error); +type func = fn(cfg: config, tasks: []task, args: arguments) (void | task | error); type command = struct { names: []str, @@ -45,17 +45,17 @@ const commands: [_]command = [ }, ]; -fn execcommand(name: str, tasks: []task, args: arguments) (void | error) = { +fn execcommand(cfg: config, name: str, tasks: []task, args: arguments) (void | error) = { for (const c .. commands) { for (const n .. c.names) { if (n == name) { - c.func(tasks, args)?; + c.func(cfg, tasks, args)?; }; }; }; }; -fn write(tasks: []task, a: arguments) (void | task | error) = { +fn write(cfg: config, tasks: []task, a: arguments) (void | task | error) = { const args = a.args; if (len(args) != 1z) { getopt::printhelp(os::stderr, "write", a.help)?; @@ -72,7 +72,7 @@ fn write(tasks: []task, a: arguments) (void | task | error) = { exec::exec(&c); }; -fn show(tasks: []task, a: arguments) (void | task | error) = { +fn show(cfg: config, tasks: []task, a: arguments) (void | task | error) = { const args = a.args; const id = strconv::stoz(args[0])?; const t = if (len(tasks) > id) { @@ -112,7 +112,7 @@ fn printtask(t: task, id: size) (void | error) = { )!; }; -fn do(tasks: []task, a: arguments) (void | task | error) = { +fn do(cfg: config, tasks: []task, a: arguments) (void | task | error) = { if (len(a.args) != 1z) { getopt::printhelp(os::stderr, "done", a.help)?; os::exit(os::status::FAILURE); @@ -123,7 +123,7 @@ fn do(tasks: []task, a: arguments) (void | task | error) = { fmt::printfln("Task {}: \"{}\" done (deleted)", id, t.name)!; }; -fn filter(tasks: []task, a: arguments) (void | task | error) = { +fn filter(cfg: config, tasks: []task, a: arguments) (void | task | error) = { const headpad = PADDING - len("name") + len("priority"); const namepad = 10 - len("id") + len("name"); fmt::printfln("id{%}{%}", @@ -155,7 +155,7 @@ fn filter(tasks: []task, a: arguments) (void | task | error) = { }; }; -fn tsv(tasks: []task, a: arguments) (void | task | error) = { +fn tsv(cfg: config, tasks: []task, a: arguments) (void | task | error) = { tsv::writerecord(os::stdout, ["id" ,"name", "priority"])!; for (let i = 0z; i < len(tasks); i += 1) { const t = tasks[i]; @@ -163,7 +163,7 @@ fn tsv(tasks: []task, a: arguments) (void | task | error) = { }; }; -fn listall(tasks: []task) void = { +fn listall(cfg: config, tasks: []task) void = { const headpad = PADDING - len("name") + len("priority"); const namepad = 10 - len("id") + len("name"); fmt::printfln("id{%}{%}", |
