Make config file parsers pluggable #1

Merged
uwiger merged 2 commits from uw-pluggable-decoders into master 2025-04-02 16:35:39 +09:00
Owner

In order to simplify deps, this PR makes config file formats pluggable. The extensions supported by default are "json" and "eterm".
The default json decoder is the one from OTP, but if one prefers another (e.g. zj), it's possible to choose that when installing the gmconfig env.

Example of adding a yaml decoder:

instrument_gmconfig() ->
    gmconfig:set_gmconfig_env(gmconfig_env()).

-spec gmconfig_env() -> gmconfig:gmconfig().
gmconfig_env() ->
    #{ ...
     , config_formats => add_yamerl() }.

add_yamerl() ->
    Default = maps:get(config_formats, gmconfig:default_gmconfig_env()),
    case maps:is_key("yaml", Default) of
        true ->
            Default;
        false ->
            Default#{"yaml" => fun yamerl_decode/1}
    end.

yamerl_decode(Bin) ->
    yamerl:decode(Bin, [{str_node_as_binary, true},
                        {map_node_format, map}]).
In order to simplify deps, this PR makes config file formats pluggable. The extensions supported by default are "json" and "eterm". The default json decoder is the one from OTP, but if one prefers another (e.g. `zj`), it's possible to choose that when installing the gmconfig env. Example of adding a yaml decoder: ```erlang instrument_gmconfig() -> gmconfig:set_gmconfig_env(gmconfig_env()). -spec gmconfig_env() -> gmconfig:gmconfig(). gmconfig_env() -> #{ ... , config_formats => add_yamerl() }. add_yamerl() -> Default = maps:get(config_formats, gmconfig:default_gmconfig_env()), case maps:is_key("yaml", Default) of true -> Default; false -> Default#{"yaml" => fun yamerl_decode/1} end. yamerl_decode(Bin) -> yamerl:decode(Bin, [{str_node_as_binary, true}, {map_node_format, map}]). ```
uwiger added 1 commit 2025-03-13 23:57:14 +09:00
uwiger requested review from dimitar.p.ivanov 2025-03-13 23:57:14 +09:00
uwiger requested review from zxq9 2025-03-13 23:57:14 +09:00
uwiger added 1 commit 2025-03-15 07:16:04 +09:00
uwiger merged commit de5d2bfb7d into master 2025-04-02 16:35:39 +09:00
Sign in to join this conversation.
No Milestone
No project
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: QPQ-AG/gmconfig#1
No description provided.