From 97864116bba944b74d42522b51bc3b19b6cdd6be Mon Sep 17 00:00:00 2001 From: zapashcanon Date: Mon, 5 Dec 2022 22:44:30 +0100 Subject: [PATCH] do not force file to exist --- src/app.ml | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/src/app.ml b/src/app.ml index d213823..9c3c619 100644 --- a/src/app.ml +++ b/src/app.ml @@ -20,14 +20,13 @@ let config_dir = let config = let filename = Filename.concat config_dir "config.scfg" in - if not @@ Sys.file_exists filename then - failwith - @@ Format.sprintf "configuration file `%s` does not exist, please create it" - filename; - Dream.log "config file: %s" filename; - match Scfg.Parse.from_file filename with - | Error e -> failwith e - | Ok config -> config + if not @@ Sys.file_exists filename then [] + else begin + Dream.log "config file: %s" filename; + match Scfg.Parse.from_file filename with + | Error e -> failwith e + | Ok config -> config + end let open_registration = match Scfg.Query.get_dir "open_registration" config with @@ -59,8 +58,9 @@ let port = let () = Dream.log "port: %d" port let hostname = + let default_hostname = Format.sprintf "localhost:%d" port in match Scfg.Query.get_dir "hostname" config with - | None -> Format.sprintf "localhost:%d" port + | None -> default_hostname | Some hostname -> Result.fold ~error:failwith ~ok:Fun.id (Scfg.Query.get_param 0 hostname) @@ -78,17 +78,15 @@ let log = let () = Dream.log "log: %b" log -let get_dirs name = - let dirs = Scfg.Query.get_dirs name config in - List.map - (fun dir -> - Result.fold ~error:failwith ~ok:Fun.id (Scfg.Query.get_param 0 dir) ) - dirs - let random_state = Random.State.make_self_init () let () = Random.set_state random_state let about = - (* TODO read from about.txt *) - "This is pellest" + let default_about = "Pellest is great !" in + match Scfg.Query.get_dir "about" config with + | None -> default_about + | Some about -> ( + match Scfg.Query.get_param 0 about with + | Error e -> failwith e + | Ok about -> about )