-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathmain.swift
49 lines (43 loc) · 1.16 KB
/
main.swift
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
// Noze.io child_process example
// - to compile in Swift 3 invoke: swift build
// - to run result: .build/debug/call-git
import streams
import child_process
import process
struct GitLogEntry {
let commit : String
let author : String
let email : String
let date : String
}
extension String {
func componentsSeparated(by c: Character) -> [ String ] {
#if swift(>=3.2)
return split(separator: c).map { String($0) }
#else
return characters.split(separator: c).map { String($0) }
#endif
}
}
spawn("git", "log", "-5", "--pretty=format:%H|%an|<%ae>|%ad")
| readlines
| through2 { lines, push, end in
let records : [ GitLogEntry ] = lines.map { line in
let fields = line.componentsSeparated(by: "|")
return GitLogEntry(
commit: fields[0],
author: fields[1],
email: fields[2],
date: fields[3]
)
}
end(nil, records)
}
| concat { (records : [ GitLogEntry ]) in
for r in records {
print("Entry:")
print(" Commit: \(r.commit)")
print(" by: \(r.author) \(r.email)")
print(" on: \(r.date)")
}
}