-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.jk
55 lines (47 loc) · 1.4 KB
/
lib.jk
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
incl libgit_wrapper;
// FIXME: This should return a Result
func gitko_init() -> bool {
libgit_init_error_code = git_libgit2_init();
if libgit_init_error_code >= 0 {
true
} else {
println_err(jinko_git_get_error());
false
}
}
type Local;
type Remote;
// FIXME: Replace all `strings` with `Maybe[String]` for builder pattern
// FIXME: Add kind: Local | Remote
type Git(url: string, local_path: string);
// FIXME: Return Result instead
func __inner_clone(git: Git) -> bool {
if jinko_git_clone(git.url, git.local_path) != 0 {
println_err("couldn't clone repository {git.url} to {git.local_path}: {jinko_git_get_error()}");
false
} else {
true
}
}
// FIXME: Return Result[] instead
func clone(repo: Git) -> bool {
if repo.local_path.is_empty().not() {
repo.__inner_clone()
} else {
// FIXME: Use future logging library
println_err("cannot clone library to empty local path");
false
}
}
func repository(url: string) -> Git {
Git(url: url, local_path: "")
}
func to_path(git: Git, path: string) -> Git {
Git(url: git.url, local_path: path)
}
// FIXME: We should think about a better way to make runtime errors... And it
// should be included in the standard library.
// Something like Log.err() which would display stuff in red
if gitko_init().not() {
println_err("couldn't initialize gitko library");
}