aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric <[email protected]>2012-09-14 09:25:03 -0500
committerEric <[email protected]>2012-09-18 10:04:32 -0700
commit085b1e92b2a2d442d76490e41f8d697a6ec704a9 (patch)
tree8d221160397d2396b47ed7ae2ea6d657c4be2fc9
parente15d768062834181bb36b73fe607208ef4c6cd8c (diff)
downloadrelx-085b1e92b2a2d442d76490e41f8d697a6ec704a9.tar.gz
relx-085b1e92b2a2d442d76490e41f8d697a6ec704a9.tar.bz2
relx-085b1e92b2a2d442d76490e41f8d697a6ec704a9.zip
handle config providers slightly differently from other providers
-rw-r--r--src/relcool.erl39
1 files changed, 37 insertions, 2 deletions
diff --git a/src/relcool.erl b/src/relcool.erl
index 2284d29..8c9363c 100644
--- a/src/relcool.erl
+++ b/src/relcool.erl
@@ -60,7 +60,40 @@ run_relcool_process(State) ->
fun() ->
rcl_state:format(State)
end),
- ok.
+ run_providers(State).
+
+%% @doc for now the 'config' provider is special in that it generates the
+%% providers used by the rest of the system. We expect the config provider to be
+%% the first provider in the system. Once the config provider is run, we get the
+%% providers again and run the rest of them (because they could have been
+%% updated by the config process).
+run_providers(State0) ->
+ [ConfigProvider | _] = rcl_state:providers(State0),
+ State1 = run_provider(ConfigProvider, State0),
+
+ Providers = rcl_state:providers(State1),
+ case Providers of
+ [ConfigProvider | Rest] ->
+ %% IF the config provider is still the first provider do not run it
+ %% again just run the rest.
+ run_providers(Rest, State1);
+ _ ->
+ run_providers(Providers, State1)
+ end,
+ init:stop(0).
+
+run_providers(Providers, State0) ->
+ lists:foldl(fun run_provider/2, State0, Providers).
+
+
+-spec run_provider(rcl_provider:t(), rcl_state:t()) -> rcl_state:t().
+run_provider(Provider, State0) ->
+ case rcl_provider:do(Provider, State0) of
+ {ok, State1} ->
+ State1;
+ E={error, _} ->
+ report_error(rcl_provider:format_error(Provider, E))
+ end.
-spec usage() -> ok.
usage() ->
@@ -73,7 +106,9 @@ report_error(Error) ->
usage(),
erlang:halt(127).
--spec to_error({error, Reason::term()}) -> string().
+-spec to_error(string() | {error, Reason::term()}) -> string().
+to_error(String) when erlang:is_list(String) ->
+ String;
to_error({error,{invalid_option_arg, Arg}}) ->
case Arg of
{goals, Goal} ->