let parse_log log =
let lines = String.split ~on:(`Character '\n') log in
let table =
List.filter_map lines ~f:(fun line ->
let cells =
String.split ~on:(`Character '\t') line
|> List.map ~f:(String.strip)
|> List.filter ~f:((<>) "")
in
match cells with
| [] | [""] -> None
| more ->
let translated =
match more with
| "start" :: date :: [] -> `Start date
| "before-cmd" :: date :: label :: cmd :: [] ->
`Before (date, label, cmd)
| "after-cmd" :: date :: label :: ret :: [] ->
`After (date, label, ret)
| "success" :: date :: [] -> `Success date
| "failure" :: date :: label :: ret :: [] ->
`Failure (date, label, ret)
| other -> `Error other
in
Some translated)
in
table