aboutsummaryrefslogtreecommitdiff
path: root/hatask.ha
blob: 493c597e153ab681f5719626895a373897a9e38f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use fmt;
use dirs;
use bufio;
use os;
use fs;
use path;
use io;
use strings;
use format::ini;

type task = struct {
	name: str,
	context: (str | void),
	tags: ([]str | void),
	priority: uint,
};

def METADATASEP: str = "----";

fn listtasks(root: str = "tasks", context: str = "*") ([]task | fs::error |
	path::error) = {
	const dirents = os::readdir(root)?;
	defer fs::dirents_free(dirents);
	let tasks: []task = [];
	for (const dirent .. dirents) {
		if (context == "*" || dirent.name == context) {
			if (fs::isdir(dirent.ftype)) {
				let buf = path::init()?;
				const p = path::push(&buf, root, dirent.name)?;
				listtasks(p)?;
			} else {
				fmt::println(dirent.name)!;
			};
		};
	};
	return tasks;
};

fn readtask(taskpath: str) (task | fs::error) = {
	const f = os::open(taskpath)?;
	defer io::close(f)!;
	const sc = bufio::newscanner(f);
	defer bufio::finish(&sc);
	for (let line => bufio::scan_line(&sc)?) {
		line = strings::trim(line);
		if (line == METADATASEP) {
			break;
		};

	};
};

export fn main() void = {
	match (listtasks()) {
	case let e: fs::error =>
		fmt::fatal(fs::strerror(e));
	case let e: path::error =>
		fmt::fatal(path::strerror(e));
	case =>
		void;
	};
};