do not force file to exist

This commit is contained in:
zapashcanon 2022-12-05 22:44:30 +01:00
parent be2a16e0b9
commit 97864116bb
No known key found for this signature in database
GPG key ID: 8981C3C62D1D28F1

View file

@ -20,14 +20,13 @@ let config_dir =
let config = let config =
let filename = Filename.concat config_dir "config.scfg" in let filename = Filename.concat config_dir "config.scfg" in
if not @@ Sys.file_exists filename then if not @@ Sys.file_exists filename then []
failwith else begin
@@ Format.sprintf "configuration file `%s` does not exist, please create it"
filename;
Dream.log "config file: %s" filename; Dream.log "config file: %s" filename;
match Scfg.Parse.from_file filename with match Scfg.Parse.from_file filename with
| Error e -> failwith e | Error e -> failwith e
| Ok config -> config | Ok config -> config
end
let open_registration = let open_registration =
match Scfg.Query.get_dir "open_registration" config with match Scfg.Query.get_dir "open_registration" config with
@ -59,8 +58,9 @@ let port =
let () = Dream.log "port: %d" port let () = Dream.log "port: %d" port
let hostname = let hostname =
let default_hostname = Format.sprintf "localhost:%d" port in
match Scfg.Query.get_dir "hostname" config with match Scfg.Query.get_dir "hostname" config with
| None -> Format.sprintf "localhost:%d" port | None -> default_hostname
| Some hostname -> | Some hostname ->
Result.fold ~error:failwith ~ok:Fun.id (Scfg.Query.get_param 0 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 () = 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_state = Random.State.make_self_init ()
let () = Random.set_state random_state let () = Random.set_state random_state
let about = let about =
(* TODO read from about.txt *) let default_about = "Pellest is great !" in
"This is pellest" 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 )