aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlban Gruin2020-09-13 20:13:32 +0200
committerAlban Gruin2020-09-13 20:14:10 +0200
commitebd49001ab9c844eaba52a19f6387dfb2a0da7af (patch)
treec7a896358f650ece575b23cb6e2e740b63cc8b3e
parenta262942eb56a962d20b3b34b637cd9cbea81b509 (diff)
ucs: add command line parameters, powered by cmdliner
Signed-off-by: Alban Gruin <alban at pa1ch dot fr>
-rw-r--r--src/dune1
-rw-r--r--src/ucs.ml42
2 files changed, 42 insertions, 1 deletions
diff --git a/src/dune b/src/dune
index c29403a..b5b0a8c 100644
--- a/src/dune
+++ b/src/dune
@@ -2,6 +2,7 @@
(name ucs)
(libraries astring
calendar
+ cmdliner
cohttp-lwt-unix
ezjsonm
lwt.unix
diff --git a/src/ucs.ml b/src/ucs.ml
index cd5f018..a789ecf 100644
--- a/src/ucs.ml
+++ b/src/ucs.ml
@@ -15,5 +15,45 @@
* along with ucs. If not, see <http://www.gnu.org/licenses/>.
*)
+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 () =
- Lwt_main.run (Server.serve "/" (Uri.of_string "/") (`TCP (`Port 8080)))
+ 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" ~doc ~exits in
+ Term.(exit @@ eval cmd)