(*--------------------------------------------------------------------------- Copyright (c) 2026 Anil Madhavapeddy . All rights reserved. SPDX-License-Identifier: ISC ---------------------------------------------------------------------------*) type t = { channel : string; topic : string; changes_file : string; monorepo_path : string; admin_emails : string list; changes_dir : string; verse_path : string option; (* Path to verse/ directory containing user monorepos *) } let default = { channel = "general"; topic = "Daily Changes"; changes_file = "DAILY-CHANGES.md"; monorepo_path = "."; admin_emails = []; changes_dir = ".changes"; verse_path = None; } let codec = Tomlt.( Table.( obj (fun channel topic changes_file monorepo_path admin_emails changes_dir verse_path -> { channel; topic; changes_file; monorepo_path; admin_emails; changes_dir; verse_path }) |> mem "channel" string ~dec_absent:default.channel ~enc:(fun c -> c.channel) |> mem "topic" string ~dec_absent:default.topic ~enc:(fun c -> c.topic) |> mem "changes_file" string ~dec_absent:default.changes_file ~enc:(fun c -> c.changes_file) |> mem "monorepo_path" string ~dec_absent:default.monorepo_path ~enc:(fun c -> c.monorepo_path) |> mem "admin_emails" (list string) ~dec_absent:default.admin_emails ~enc:(fun c -> c.admin_emails) |> mem "changes_dir" string ~dec_absent:default.changes_dir ~enc:(fun c -> c.changes_dir) |> opt_mem "verse_path" string ~enc:(fun c -> c.verse_path) |> finish)) let load_from_path path = let content = Eio.Path.load path in match Tomlt_bytesrw.decode_string codec content with | Ok config -> config | Error e -> failwith (Tomlt.Error.to_string e) let load_from_path_opt path = try let content = Eio.Path.load path in match Tomlt_bytesrw.decode_string codec content with | Ok config -> Some config | Error _ -> None with _ -> None let xdg ~fs = Xdge.create fs "poe" let load_xdg ~fs = let xdg = xdg ~fs in match Xdge.find_config_file xdg "config.toml" with | Some path -> load_from_path path | None -> failwith "No poe configuration found in XDG config directories" let load_xdg_opt ~fs = let xdg = xdg ~fs in match Xdge.find_config_file xdg "config.toml" with | Some path -> load_from_path_opt path | None -> None let load ~fs path = let open Eio.Path in load_from_path (fs / path) let load_opt ~fs path = let open Eio.Path in load_from_path_opt (fs / path) let config_dir ~fs = let xdg = xdg ~fs in Xdge.config_dir xdg