(* * Copyright (C) 2020 Alban Gruin * * ucs is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published * by the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * ucs is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with ucs. If not, see . *) open Cmdliner let tcp = (fun s -> match int_of_string_opt s with | Some p when p >= 0 && p < 65536 -> `Ok p | Some p -> `Error (Printf.sprintf "invalid value `%d', expected a number \ between 0 and 65535" p) | None -> `Error (Printf.sprintf "invalid value `%s', expected an \ integer" s)), Format.pp_print_int let base_url = let doc = "Base URL for this instance" in Arg.(required & opt (some string) None & info ["b"; "base"] ~doc) let celcat_url = let doc = "Celcat URL" in Arg.(required & opt (some string) None & info ["c"; "celcat"] ~doc) let port = let doc = "TCP port" in Arg.(value & opt tcp 8080 & info ["p"; "port"] ~doc) let socket = let doc = "UNIX socket" in Arg.(value & opt (some string) None & info ["s"; "socket"] ~doc) let () = let run base_url celcat_url port socket = let celcat_uri = Uri.of_string celcat_url and mode = match socket with | Some s -> `Unix_domain_socket (`File s) | None -> `TCP (`Port port) in Lwt_main.run (Server.serve base_url celcat_uri mode) in let cmd = let doc = "micro celcatsanitizer: convert celcat \ calendar to ICS files, on the fly." and exits = Term.default_exits in Term.(const run $ base_url $ celcat_url $ port $ socket), Term.info "ucs" ~version:"0.1.0" ~doc ~exits in Term.(exit @@ eval cmd)