diff options
author | José Valim <[email protected]> | 2019-01-16 15:25:21 +0100 |
---|---|---|
committer | José Valim <[email protected]> | 2019-03-01 06:37:50 -0800 |
commit | d92eb79322fa4ee45ce1c0c7c4ed8a573673474b (patch) | |
tree | c8d6fc3b1ffde1ee4c081e63c1bb416a7e16452a /lib/kernel/src/application.erl | |
parent | 06f43998fd9dcc5afec0cfb13bb60549fe20d663 (diff) | |
download | otp-d92eb79322fa4ee45ce1c0c7c4ed8a573673474b.tar.gz otp-d92eb79322fa4ee45ce1c0c7c4ed8a573673474b.tar.bz2 otp-d92eb79322fa4ee45ce1c0c7c4ed8a573673474b.zip |
Add application:set_env/1 and application:set_env/2
It is equivalent to calling application:set_env/4 on
each application individually, except it is more efficient.
When given duplicate apps or duplicate keys, set_env/1
and set_env/2 will warn. The warning will also be emitted
during boot:
$ erl -config dupkeys.config -s erlang halt
2019-02-27 11:16:02.653100 application: kernel; duplicate parameter: key1
=WARNING REPORT==== 27-Feb-2019::11:16:02.653100 ===
application: kernel; duplicate parameter: key1
$ erl -config dupapps.config -s erlang halt
2019-02-27 11:16:02.653100 duplicate application config: kernel
=WARNING REPORT==== 27-Feb-2019::11:16:02.653100 ===
duplicate application config: kernel
Prior to this patch, the behaviour was unspecified,
and duplicate keys and duplicate apps would behave
different depending on the amount of config, the name
of the config files, and how those configs would be
listed. The goal is to raise an error in the future.
Diffstat (limited to 'lib/kernel/src/application.erl')
-rw-r--r-- | lib/kernel/src/application.erl | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/lib/kernel/src/application.erl b/lib/kernel/src/application.erl index bc6be2f8f5..5c2e981e4b 100644 --- a/lib/kernel/src/application.erl +++ b/lib/kernel/src/application.erl @@ -25,7 +25,7 @@ which_applications/0, which_applications/1, loaded_applications/0, permit/2]). -export([ensure_started/1, ensure_started/2]). --export([set_env/3, set_env/4, unset_env/2, unset_env/3]). +-export([set_env/1, set_env/2, set_env/3, set_env/4, unset_env/2, unset_env/3]). -export([get_env/1, get_env/2, get_env/3, get_all_env/0, get_all_env/1]). -export([get_key/1, get_key/2, get_all_key/0, get_all_key/1]). -export([get_application/0, get_application/1, info/0]). @@ -279,6 +279,26 @@ loaded_applications() -> info() -> application_controller:info(). +-spec set_env(Config) -> 'ok' when + Config :: [{Application, Env}], + Application :: atom(), + Env :: [{Par :: atom(), Val :: term()}]. + +set_env(Config) when is_list(Config) -> + set_env(Config, []). + +-spec set_env(Config, Opts) -> 'ok' when + Config :: [{Application, Env}], + Application :: atom(), + Env :: [{Par :: atom(), Val :: term()}], + Opts :: [{timeout, timeout()} | {persistent, boolean()}]. + +set_env(Config, Opts) when is_list(Config), is_list(Opts) -> + case application_controller:set_env(Config, Opts) of + ok -> ok; + {error, Msg} -> erlang:error({badarg, Msg}, [Config, Opts]) + end. + -spec set_env(Application, Par, Val) -> 'ok' when Application :: atom(), Par :: atom(), |