選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

52 行
2.2 KiB

  1. %% -*- erlang-indent-level: 4;indent-tabs-mode: nil -*-
  2. %% ex: ts=4 sw=4 et
  3. -module(rebar_prv_as).
  4. -behaviour(provider).
  5. -export([init/1,
  6. do/1,
  7. format_error/1]).
  8. -include("rebar.hrl").
  9. -define(PROVIDER, as).
  10. -define(DEPS, []).
  11. %% ===================================================================
  12. %% Public API
  13. %% ===================================================================
  14. -spec init(rebar_state:t()) -> {ok, rebar_state:t()}.
  15. init(State) ->
  16. State1 = rebar_state:add_provider(State, providers:create([{name, ?PROVIDER},
  17. {module, ?MODULE},
  18. {bare, false},
  19. {deps, ?DEPS},
  20. {example, "rebar3 as <profile1>,<profile2>,... <task1>, <task2>, ..."},
  21. {short_desc, "Higher order provider for running multiple tasks in a sequence as a certain profiles."},
  22. {desc, ""},
  23. {opts, [{profile, undefined, undefined, string, "Profiles to run as."}]}])),
  24. {ok, State1}.
  25. -spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
  26. do(State) ->
  27. [Profile | Rest] = rebar_state:command_args(State),
  28. Tasks = args_to_tasks(Rest),
  29. Profiles = [list_to_atom(X) || X <- string:tokens(Profile, ",")],
  30. State1 = rebar_state:apply_profiles(State, Profiles),
  31. lists:foldl(fun(TaskArgs, {ok, StateAcc}) ->
  32. [TaskStr | Args] = string:tokens(TaskArgs, " "),
  33. Task = list_to_atom(TaskStr),
  34. StateAcc1 = rebar_state:set(StateAcc, task, Task),
  35. StateAcc2 = rebar_state:command_args(StateAcc1, Args),
  36. rebar_core:process_command(StateAcc2, Task)
  37. end, {ok, State1}, Tasks).
  38. -spec format_error(any()) -> iolist().
  39. format_error(Reason) ->
  40. io_lib:format("~p", [Reason]).
  41. args_to_tasks(Args) ->
  42. [string:strip(T) || T <- string:tokens(string:join(Args, " "), ",")].