aboutsummaryrefslogtreecommitdiffstats
path: root/src/rcl_prv_config.erl
diff options
context:
space:
mode:
authorEric <[email protected]>2012-09-18 10:03:49 -0700
committerEric <[email protected]>2012-09-18 10:03:49 -0700
commit5a58c7dc317674dff20e267baecdb3414af516ff (patch)
treed4c097396043befe5b0c870cf938bbcaae38182a /src/rcl_prv_config.erl
parent96e42872d5e5d6ff241d6070194156a21e628208 (diff)
downloadrelx-5a58c7dc317674dff20e267baecdb3414af516ff.tar.gz
relx-5a58c7dc317674dff20e267baecdb3414af516ff.tar.bz2
relx-5a58c7dc317674dff20e267baecdb3414af516ff.zip
support arbitrary data in configs (per provider state)
Diffstat (limited to 'src/rcl_prv_config.erl')
-rw-r--r--src/rcl_prv_config.erl23
1 files changed, 17 insertions, 6 deletions
diff --git a/src/rcl_prv_config.erl b/src/rcl_prv_config.erl
index 6036097..3b92a3b 100644
--- a/src/rcl_prv_config.erl
+++ b/src/rcl_prv_config.erl
@@ -12,7 +12,7 @@
%% API
-export([init/1,
do/1,
- format/1]).
+ format_error/1]).
%%%===================================================================
@@ -24,15 +24,18 @@
init(State) ->
{ok, State}.
-%% @doc
-%%
+%% @doc parse all the configs currently specified in the state,
+%% populating the state as a result.
-spec do(rcl_state:t()) ->{ok, rcl_state:t()} | {error, Reason::term()}.
do(State) ->
ConfigFiles = rcl_state:config_files(State),
lists:foldl(fun load_config/2, {ok, State}, ConfigFiles).
-format({error, {consult, Reason}}) ->
- file:format_error(Reason).
+-spec format_error({error, Reason::term()}) -> iolist().
+format_error({error, {consult, Reason}}) ->
+ file:format_error(Reason);
+format_error({error, {invalid_term, Term}}) ->
+ io_lib:format("Invalid term in config file: ~p", [Term]).
%%%===================================================================
%%% Internal Functions
@@ -51,6 +54,8 @@ load_config(ConfigFile, {ok, State}) ->
ok = file:set_cwd(CurrentCwd),
Result.
+load_terms({default_release, RelName, RelVsn}, {ok, State}) ->
+ {ok, rcl_state:default_release(State, RelName, RelVsn)};
load_terms({paths, Paths}, {ok, State}) ->
code:add_pathsa([filename:absname(Path) || Path <- Paths]),
{ok, State};
@@ -88,7 +93,13 @@ load_terms({release, {RelName, Vsn}, {erts, ErtsVsn},
E;
{ok, Release1} ->
{ok, rcl_state:add_release(State, Release1)}
- end.
+ end;
+load_terms({Name, Value}, {ok, State})
+ when erlang:is_atom(Name) ->
+ {ok, rcl_state:put(State, Name, Value)};
+load_terms(InvalidTerm, _) ->
+ {error, {invalid_term, InvalidTerm}}.
+
gen_providers(Providers, State) ->
lists:foldl(fun(ProviderName, {Providers1, {ok, State1}}) ->