@@ -242,19 +242,43 @@ consult_config([], ReportMissingConfig) ->
242
242
{undefined , #{}};
243
243
consult_config ([Path | Paths ], ReportMissingConfig ) ->
244
244
? LOG_INFO (" Reading config file. path=~p " , [Path ]),
245
- try consult_file (Path ) of
246
- [] -> {Path , #{}};
247
- [Config ] -> {Path , Config };
248
- {ok , Config } -> {Path , maps :from_list (Config )};
249
- {error , Reason } ->
250
- ? LOG_WARNING ( " Could not read config file: path=~p class=~p error=~p "
251
- , [Path , error , Reason ]),
252
- consult_config (Paths , ReportMissingConfig )
245
+ Result =
246
+ case filename :extension (Path ) of
247
+ " .yaml" ->
248
+ try_yaml (Path );
249
+ " .config" ->
250
+ try_eterm (Path , _TryYaml = true )
251
+ end ,
252
+ case Result of
253
+ {ok , Config } ->
254
+ {Path , Config };
255
+ {error , Class , Error } ->
256
+ ? LOG_WARNING (" Could not read config file: path=~p class=~p error=~p " ,
257
+ [Path , Class , Error ]),
258
+ consult_config (Paths , ReportMissingConfig )
259
+ end .
260
+
261
+ -spec try_yaml (path ()) -> {ok , map ()} | {error , atom (), term ()}.
262
+ try_yaml (Path ) ->
263
+ try yamerl :decode_file (Path , [{map_node_format , map }]) of
264
+ [] ->
265
+ {ok , #{}};
266
+ [Config ] ->
267
+ {ok , Config }
253
268
catch
254
269
Class :Error ->
255
- ? LOG_WARNING ( " Could not read config file: path=~p class=~p error=~p "
256
- , [Path , Class , Error ]),
257
- consult_config (Paths , ReportMissingConfig )
270
+ {error , Class , Error }
271
+ end .
272
+
273
+ -spec try_eterm (path (), boolean ()) -> {ok , map ()} | {error , atom (), term ()}.
274
+ try_eterm (Path , TryYaml ) ->
275
+ case consult_file (Path ) of
276
+ {ok , Config } ->
277
+ {ok , maps :from_list (Config )};
278
+ {error , _ } when TryYaml ->
279
+ try_yaml (Path );
280
+ {error , Reason } ->
281
+ {error , error , Reason }
258
282
end .
259
283
260
284
-spec consult_file (path ()) -> [map ()] | {ok , [term ()]} | {error , term ()}.
0 commit comments