Decompose Config.config to Config.of_path

This commit is contained in:
Stavros Polymenis 2017-10-25 22:07:48 +01:00
parent 9a9f8ecd67
commit b1851c4426
2 changed files with 15 additions and 4 deletions

View File

@ -26,6 +26,13 @@ module Validation = struct
end
module Path = struct
let of_string str =
if Sys.file_exists str then
match Fpath.v str with
| path -> Ok path
| exception (Invalid_argument msg) -> Error ("Invalid path " ^ msg)
else Error (str ^ " not found")
let path_exists x = Fpath.to_string x |> Sys.file_exists
let conventional_paths =
@ -59,9 +66,8 @@ end
module Make (S : Store) = struct
include S
let config filename = match Path.with_file filename with
| Ok filepath -> S.from_path filepath
| Error s -> Error s
let of_path path = S.from_path path
let (&>) = (&>)

View File

@ -5,7 +5,12 @@ module Lpath = Logarion.Lpath
let conf () =
let module Config = Confix.Config.Make (Confix.ConfixToml) in
let archive_res = Config.config "config.toml" |> Config.to_record C.of_config in
let archive_res =
let open Confix.Config in
Confix.Config.Path.with_file "config.toml"
&> Config.from_path
|> Config.to_record C.of_config
in
match archive_res with
| Ok config -> config
| Error str -> prerr_endline str; exit 1