View raw

1 (** Reading and validating the TOML configuration. 2 3 The file is looked up at [$OGIT_CONFIG], then 4 [$XDG_CONFIG_HOME/ogit/config.toml], then [/etc/ogit/config.toml]. When no 5 file is chosen explicitly a missing one is fine and {!default} applies; a 6 file that exists but is malformed or invalid is always an error, so a 7 mistake never silently degrades into defaults. 8 9 {!to_table} and {!write_file} support the [ogit-write-config] executable, 10 which emits a config file pre-filled with the defaults. *) 11 12 (** {1 Configuration record} *) 13 14 type t = { 15 user_name : string; 16 default_branch : string; 17 git_project_root : string; 18 commits_max_displayed : int; 19 root_title : string; 20 nav_logo : string; 21 host : string; 22 port : int; 23 favorite_repositories : string list; 24 archived_repositories : string list; 25 } 26 (** All settings that influence the server's behaviour. *) 27 28 (** {1 Errors} *) 29 30 type load_error = 31 | Not_found of string 32 | Parse_error of string 33 | Invalid_value of string 34 | Io_error of string 35 36 val pp_load_error : Format.formatter -> load_error -> unit 37 (** Format a load error for diagnostics. *) 38 39 val show_load_error : load_error -> string 40 (** Render a load error as a string. *) 41 42 (** {1 Defaults} *) 43 44 val default : t 45 (** The configuration used when no file is found. *) 46 47 (** {1 Loading} *) 48 49 val load : unit -> (t, load_error) result 50 (** Locate and parse the configuration file, or return {!default} when no 51 implicit file exists. An explicit [$OGIT_CONFIG] that is missing or 52 malformed is always an error. *) 53 54 val read_file : ?file:string -> unit -> (t, load_error) result 55 (** Parse a specific configuration file. *) 56 57 (** {1 Serialisation} *) 58 59 val to_table : t -> Toml.Types.table 60 (** Convert a configuration record to a TOML table, suitable for writing back to 61 disk. *) 62 63 val write_file : ?file:string -> Toml.Types.table -> unit 64 (** Write a TOML table to the given file, or to the default configuration path. 65 *) 66 67 (** {1 Internals exposed for tooling} *) 68 69 val locate_config_file : unit -> string 70 (** Return the path that would be used for the configuration file, following the 71 [$OGIT_CONFIG] then [$XDG_CONFIG_HOME] then [/etc] resolution order. Useful 72 for diagnostic tools. *) 73