mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-24 16:23:40 +01:00
Group all duplicated list-like options into a single option
This commit is contained in:
parent
94b74c0cbe
commit
b7b76cc38b
@ -555,15 +555,11 @@ pre_validate(Y1) ->
|
|||||||
#{hosts => ejabberd_options:opt_type(hosts),
|
#{hosts => ejabberd_options:opt_type(hosts),
|
||||||
loglevel => ejabberd_options:opt_type(loglevel),
|
loglevel => ejabberd_options:opt_type(loglevel),
|
||||||
version => ejabberd_options:opt_type(version),
|
version => ejabberd_options:opt_type(version),
|
||||||
host_config => econf:map(econf:binary(), econf:any()),
|
'_' => econf:any()},
|
||||||
append_host_config => econf:map(econf:binary(), econf:any()),
|
|
||||||
modules => ejabberd_options:opt_type(modules),
|
|
||||||
'_' => econf:any()},
|
|
||||||
[{required, [hosts]}]),
|
[{required, [hosts]}]),
|
||||||
Y1) of
|
Y1) of
|
||||||
{ok, Y2} ->
|
{ok, Y2} ->
|
||||||
{ok, group_duplicated_options(
|
{ok, group_duplicated_options(Y2)};
|
||||||
Y2, [append_host_config, host_config, modules])};
|
|
||||||
Err ->
|
Err ->
|
||||||
Err
|
Err
|
||||||
end.
|
end.
|
||||||
@ -773,16 +769,14 @@ set_node_start(UnixTime) ->
|
|||||||
set_loglevel(Level) ->
|
set_loglevel(Level) ->
|
||||||
ejabberd_logger:set(Level).
|
ejabberd_logger:set(Level).
|
||||||
|
|
||||||
-spec group_duplicated_options([{atom(), term()}], [atom()]) -> [{atom(), term()}].
|
%% All duplicated options having list-values are grouped
|
||||||
group_duplicated_options(Y1, Options) ->
|
%% into a single option with all list-values being concatenated
|
||||||
{Y2, Y3} = lists:partition(
|
-spec group_duplicated_options([{atom(), term()}]) -> [{atom(), term()}].
|
||||||
fun({Option, _}) ->
|
group_duplicated_options(Y1) ->
|
||||||
lists:member(Option, Options)
|
{Y2, D} = lists:mapfoldl(
|
||||||
end, Y1),
|
fun({Option, Values}, Acc) when is_list(Values) ->
|
||||||
lists:foldl(
|
{[], dict:append_list(Option, Values, Acc)};
|
||||||
fun(Option, Y4) ->
|
({Option, Value}, Acc) ->
|
||||||
case lists:flatten(proplists:get_all_values(Option, Y2)) of
|
{{Option, Value}, Acc}
|
||||||
[] -> Y4;
|
end, dict:new(), Y1),
|
||||||
Values -> [{Option, Values}|Y4]
|
lists:flatten(Y2) ++ dict:to_list(D).
|
||||||
end
|
|
||||||
end, Y3, Options).
|
|
||||||
|
Loading…
Reference in New Issue
Block a user