Author: Pedro Lucas Porcellis <porcellis@eletrotupi.com>
beterrabad: load services and list them
cmd/beterrabad/main.ha | 59 ++++++++++++++++++++++++++++++++++++++++++++
diff --git a/cmd/beterrabad/main.ha b/cmd/beterrabad/main.ha new file mode 100644 index 0000000000000000000000000000000000000000..3e5ff18eeea5561650dd163edbfc0a603b5c8ff9 --- /dev/null +++ b/cmd/beterrabad/main.ha @@ -0,0 +1,59 @@ +use beterraba; +use os; +use fs; +use io; +use strings; +use path; +use fmt; + +// TODO: Log should be store in XDG_DATA_STATE? +// TODO: Write opts and flesh cli a little better +// TODO: Lookup files on the default systemd place and allow user to config +// where are those files +// TODO: Write a lock file + +export fn main() void = { + fmt::println("Hello world")!; + + const servdir = "/home/eletrotupi/.config/systemd/user"; + let servnames: []str = []; + let services: []beterraba::servdef = []; + defer free(servnames); + defer free(services); + + const it = os::iter(servdir)!; + defer os::finish(it); + + for (true) { + match (fs::next(it)) { + case let ent: fs::dirent => + if (ent.name == "." || ent.name == "..") { + continue; + }; + + if (strings::hassuffix(ent.name, ".service")) { + append(servnames, strings::dup(ent.name)); + }; + + case void => + break; + }; + }; + + for (let i = 0z; i < len(servnames); i += 1) { + const servpath = path::join(servdir, servnames[i]); + const servfile = os::open(servpath)!; + + append(services, beterraba::parse(servfile)); + }; + + fmt::println("Services found:")!; + for (let i = 0z; i < len(services); i += 1) { + fmt::printfln("\t {} - Cmd: {}", + services[i].name, services[i].cmd)!; + }; + + for (let i = 0z; i < len(services); i += 1) { + beterraba::finish(&services[i]); + }; +};