From 781d4d76ac89d7184214e44523a720e23de781bc Mon Sep 17 00:00:00 2001 From: Pavel Khusainov Date: Wed, 29 Jul 2015 09:56:29 +0300 Subject: Possibility for plugins to create custom actions/tasks Before this commit user side provider wasn't able to create custom action. Now we're parsing actions/targets in `rlx_cmd_args` we didn't check them, just converting to atoms. In order to display error message about wrong action, we have to add another check in `relx:run_providers` function. --- src/rlx_cmd_args.erl | 46 +++++++++++++--------------------------------- 1 file changed, 13 insertions(+), 33 deletions(-) (limited to 'src/rlx_cmd_args.erl') diff --git a/src/rlx_cmd_args.erl b/src/rlx_cmd_args.erl index 309282e..b64c05d 100644 --- a/src/rlx_cmd_args.erl +++ b/src/rlx_cmd_args.erl @@ -33,19 +33,14 @@ {ok, {rlx_state:t(), [string()]}} | relx:error(). args2state(Opts, Targets) -> - case convert_targets(Targets) of - {ok, AtomizedTargets} -> - case run_creates(Opts) of - Error = {error, _} -> - Error; - {ok, CommandLineConfig} -> - RelName = rlx_util:to_atom(proplists:get_value(relname, Opts, undefined)), - RelVsn = proplists:get_value(relvsn, Opts, undefined), - handle_config(Opts, AtomizedTargets, - [{default_release, {RelName, RelVsn}} | CommandLineConfig]) - end; - Error -> - Error + case run_creates(Opts) of + Error = {error, _} -> + Error; + {ok, CommandLineConfig} -> + RelName = rlx_util:to_atom(proplists:get_value(relname, Opts, undefined)), + RelVsn = proplists:get_value(relvsn, Opts, undefined), + handle_config(Opts, convert_targets(Targets), + [{default_release, {RelName, RelVsn}} | CommandLineConfig]) end. -spec format_error(Reason::term()) -> iolist(). @@ -80,9 +75,7 @@ format_error({not_directory, Dir}) -> io_lib:format("Library directory does not exist: ~s", [Dir]); format_error({invalid_log_level, LogLevel}) -> io_lib:format("Invalid log level specified -V ~p, log level must be in the" - " range 0..3", [LogLevel]); -format_error({invalid_target, Target}) -> - io_lib:format("Invalid action specified: ~s", [Target]). + " range 0..3", [LogLevel]). %%%=================================================================== %%% Internal Functions @@ -102,24 +95,11 @@ handle_config(Opts, Targets, CommandLineConfig) -> end end. --spec convert_targets([string()]) -> {ok, [rlx_state:action()]} | relx:error(). +-spec convert_targets([string()]) -> [rlx_state:action()]. +convert_targets([]) -> + [release]; convert_targets(Targets) -> - convert_targets(Targets, []). - --spec convert_targets([string()], [rlx_state:action()]) -> - {ok, [rlx_state:action()]} | relx:error(). -convert_targets([], []) -> - {ok, [release]}; -convert_targets([], Acc) -> - {ok, lists:reverse(Acc)}; -convert_targets(["release" | T], Acc) -> - convert_targets(T, [release | Acc]); -convert_targets(["relup" | T], Acc) -> - convert_targets(T, [relup | Acc]); -convert_targets(["tar" | T], Acc) -> - convert_targets(T, [tar | Acc]); -convert_targets([Target | _T], _Acc) -> - ?RLX_ERROR({invalid_target, Target}). + lists:map(fun list_to_atom/1, Targets). -spec validate_config(file:filename() | list() | undefined) -> {ok, file:filename() | list() | undefined} | relx:error(). -- cgit v1.2.3