about summary refs log tree commit diff
path: root/src/logbook.ml
blob: 2da26c32de495f0a5f90d4da2630b9f94e0188b0 (plain) (blame)
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
open Lwt
open Lwt.Infix

let parse_file f =
  Lwt_io.with_file Lwt_io.Input f (fun c ->
    Lwt_io.read c >>= (fun s ->
      return (Angstrom.parse_only Log.log_parser (`String s))))

let input_file = ref None
let privacy = ref Log.Public

let arglist =
  [ ("--file", Arg.String (fun f -> input_file := Some f), "log file to use");
    ("--private", Arg.Unit (fun () -> privacy := Log.Private),
    "set privacy level of output to private");
    ("--public", Arg.Unit (fun () -> privacy := Log.Public),
    "set privacy level of output to public");
    ("--semi-private", Arg.Unit (fun () -> privacy := Log.Semi_private),
    "set privacy level of output to semi-private");
  ]

let usage = Sys.argv.(0) ^ " --file [file.log] [--public | --private | --semi-private]"

let _ =
  Arg.parse arglist (fun _ -> ()) usage;
  match !input_file with
  | None -> print_endline "No file supplied"
  | Some f -> let log = Lwt_main.run (parse_file f >>= fun log ->
      match log with
      | Result.Error msg -> failwith msg
      | Result.Ok log -> return log)
  in print_string (Jg_template.from_string
    Logbook_template.template
    ~models:(Logbook_models.model_of_log !privacy log))