Decompose Config.config to Config.of_path
This commit is contained in:
parent
9a9f8ecd67
commit
b1851c4426
@ -26,6 +26,13 @@ module Validation = struct
|
|||||||
end
|
end
|
||||||
|
|
||||||
module Path = struct
|
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 path_exists x = Fpath.to_string x |> Sys.file_exists
|
||||||
|
|
||||||
let conventional_paths =
|
let conventional_paths =
|
||||||
@ -59,9 +66,8 @@ end
|
|||||||
|
|
||||||
module Make (S : Store) = struct
|
module Make (S : Store) = struct
|
||||||
include S
|
include S
|
||||||
let config filename = match Path.with_file filename with
|
|
||||||
| Ok filepath -> S.from_path filepath
|
let of_path path = S.from_path path
|
||||||
| Error s -> Error s
|
|
||||||
|
|
||||||
let (&>) = (&>)
|
let (&>) = (&>)
|
||||||
|
|
||||||
|
@ -5,7 +5,12 @@ module Lpath = Logarion.Lpath
|
|||||||
|
|
||||||
let conf () =
|
let conf () =
|
||||||
let module Config = Confix.Config.Make (Confix.ConfixToml) in
|
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
|
match archive_res with
|
||||||
| Ok config -> config
|
| Ok config -> config
|
||||||
| Error str -> prerr_endline str; exit 1
|
| Error str -> prerr_endline str; exit 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user