summaryrefslogtreecommitdiff
path: root/src/rebar_prv_as.erl
diff options
context:
space:
mode:
authorFred Hebert <mononcqc@ferd.ca>2014-12-16 14:53:26 -0500
committerFred Hebert <mononcqc@ferd.ca>2014-12-16 14:53:26 -0500
commitb5500c7301eb6017d956b041daf4001d7b6cb3ff (patch)
treeb698186b6cfe8d64c3a8951748f838a734932998 /src/rebar_prv_as.erl
parent0672fc45b797b9a496e5bf7797d2b7168f16ca42 (diff)
parent3998dfb049f8e48c4595b72913837a0b8095a0fe (diff)
Merge pull request #56 from tsloughter/profile_deps
rewrite profiles
Diffstat (limited to 'src/rebar_prv_as.erl')
-rw-r--r--src/rebar_prv_as.erl52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/rebar_prv_as.erl b/src/rebar_prv_as.erl
new file mode 100644
index 0000000..1ad22ed
--- /dev/null
+++ b/src/rebar_prv_as.erl
@@ -0,0 +1,52 @@
+%% -*- erlang-indent-level: 4;indent-tabs-mode: nil -*-
+%% ex: ts=4 sw=4 et
+
+-module(rebar_prv_as).
+
+-behaviour(provider).
+
+-export([init/1,
+ do/1,
+ format_error/1]).
+
+-include("rebar.hrl").
+
+-define(PROVIDER, as).
+-define(DEPS, []).
+
+%% ===================================================================
+%% Public API
+%% ===================================================================
+
+-spec init(rebar_state:t()) -> {ok, rebar_state:t()}.
+init(State) ->
+ State1 = rebar_state:add_provider(State, providers:create([{name, ?PROVIDER},
+ {module, ?MODULE},
+ {bare, false},
+ {deps, ?DEPS},
+ {example, "rebar3 as <profile1>,<profile2>,... <task1>, <task2>, ..."},
+ {short_desc, "Higher order provider for running multiple tasks in a sequence as a certain profiles."},
+ {desc, ""},
+ {opts, [{profile, undefined, undefined, string, "Profiles to run as."}]}])),
+ {ok, State1}.
+
+-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
+do(State) ->
+ [Profile | Rest] = rebar_state:command_args(State),
+ Tasks = args_to_tasks(Rest),
+ Profiles = [list_to_atom(X) || X <- string:tokens(Profile, ",")],
+ State1 = rebar_state:apply_profiles(State, Profiles),
+ lists:foldl(fun(TaskArgs, {ok, StateAcc}) ->
+ [TaskStr | Args] = string:tokens(TaskArgs, " "),
+ Task = list_to_atom(TaskStr),
+ StateAcc1 = rebar_state:set(StateAcc, task, Task),
+ StateAcc2 = rebar_state:command_args(StateAcc1, Args),
+ rebar_core:process_command(StateAcc2, Task)
+ end, {ok, State1}, Tasks).
+
+-spec format_error(any()) -> iolist().
+format_error(Reason) ->
+ io_lib:format("~p", [Reason]).
+
+args_to_tasks(Args) ->
+ [string:strip(T) || T <- string:tokens(string:join(Args, " "), ",")].