aboutsummaryrefslogtreecommitdiffstats
path: root/src/relx.erl
diff options
context:
space:
mode:
authorTristan Sloughter <[email protected]>2015-08-22 16:47:22 -0500
committerTristan Sloughter <[email protected]>2015-08-22 16:47:22 -0500
commitb8d1267dc23b048646262827dae67f93f20a7d46 (patch)
tree81ac9de2e2016934d2bdb9f3354d8e11fc1ebb76 /src/relx.erl
parent0c7bc0422d1cd85eb1b627406316a6508b2d7b9e (diff)
parent781d4d76ac89d7184214e44523a720e23de781bc (diff)
downloadrelx-b8d1267dc23b048646262827dae67f93f20a7d46.tar.gz
relx-b8d1267dc23b048646262827dae67f93f20a7d46.tar.bz2
relx-b8d1267dc23b048646262827dae67f93f20a7d46.zip
Merge pull request #381 from alvelcom/user-actions
Possibility for plugins to create custom actions/tasks
Diffstat (limited to 'src/relx.erl')
-rw-r--r--src/relx.erl54
1 files changed, 38 insertions, 16 deletions
diff --git a/src/relx.erl b/src/relx.erl
index eb3b969..d2dd797 100644
--- a/src/relx.erl
+++ b/src/relx.erl
@@ -224,6 +224,8 @@ format_error({opt_parse, {invalid_option, Opt}}) ->
io_lib:format("invalid option ~s~n", [Opt]);
format_error({opt_parse, Arg}) ->
io_lib:format("~p~n", [Arg]);
+format_error({invalid_action, Action}) ->
+ io_lib:format("Invalid action specified: ~p~n", [Action]);
format_error({error, {relx, Reason}}) ->
format_error(Reason);
format_error({error, {Module, Reason}}) ->
@@ -248,27 +250,47 @@ run_relx_process(State) ->
run_providers(State0) ->
case rlx_config:do(State0) of
{ok, State1} ->
- Actions = rlx_state:actions(State0),
-
+ Actions = rlx_state:actions(State1),
AllProviders = rlx_state:providers(State1),
- TargetProviders = lists:flatmap(fun(Target) ->
- providers:get_target_providers(Target, AllProviders)
- end, Actions),
- Providers1 = lists:map(fun(P) ->
- providers:get_provider(P, AllProviders)
- end, TargetProviders),
-
- %% Unique Sort Providers
- Providers2 = providers:process_deps(Providers1, AllProviders),
-
- RootDir = rlx_state:root_dir(State1),
- ok = file:set_cwd(RootDir),
- Result = lists:foldl(fun run_provider/2, {ok, State1}, Providers2),
- handle_output(State1, rlx_state:caller(State1), Result);
+ case check_actions_correctness(Actions, AllProviders) of
+ ok ->
+ run_providers_for_actions(Actions, State1);
+ Err ->
+ Err
+ end;
Err ->
Err
end.
+check_actions_correctness(Actions, Providers) ->
+ lists:foldl(fun(Action, ok) ->
+ case providers:get_provider(Action, Providers) of
+ not_found ->
+ ?RLX_ERROR({invalid_action, Action});
+ _ ->
+ ok
+ end;
+ (_Action, Error) ->
+ Error
+ end, ok, Actions).
+
+run_providers_for_actions(Actions, State) ->
+ AllProviders = rlx_state:providers(State),
+ TargetProviders = lists:flatmap(fun(Target) ->
+ providers:get_target_providers(Target, AllProviders)
+ end, Actions),
+ Providers1 = lists:map(fun(P) ->
+ providers:get_provider(P, AllProviders)
+ end, TargetProviders),
+
+ %% Unique Sort Providers
+ Providers2 = providers:process_deps(Providers1, AllProviders),
+
+ RootDir = rlx_state:root_dir(State),
+ ok = file:set_cwd(RootDir),
+ Result = lists:foldl(fun run_provider/2, {ok, State}, Providers2),
+ handle_output(State, rlx_state:caller(State), Result).
+
handle_output(State, command_line, E={error, _}) ->
report_error(State, E),
init:stop(127);