diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/rebar.app.src | 3 | ||||
-rw-r--r-- | src/rebar3.erl | 11 | ||||
-rw-r--r-- | src/rebar_core.erl | 12 | ||||
-rw-r--r-- | src/rebar_prv_as.erl | 52 | ||||
-rw-r--r-- | src/rebar_prv_do.erl | 12 |
5 files changed, 70 insertions, 20 deletions
diff --git a/src/rebar.app.src b/src/rebar.app.src index 5ef2c2f..5f18321 100644 --- a/src/rebar.app.src +++ b/src/rebar.app.src @@ -22,7 +22,8 @@ {log_level, warn}, %% any_dir processing modules - {providers, [rebar_prv_clean, + {providers, [rebar_prv_as, + rebar_prv_clean, rebar_prv_deps, rebar_prv_dialyzer, rebar_prv_do, diff --git a/src/rebar3.erl b/src/rebar3.erl index 368ba68..b325dc8 100644 --- a/src/rebar3.erl +++ b/src/rebar3.erl @@ -127,7 +127,7 @@ run_aux(State, GlobalPluginProviders, RawArgs) -> State5 = rebar_state:create_logic_providers(AllProviders, State4), {Task, Args} = parse_args(RawArgs), - rebar_core:process_command(rebar_state:command_args(State5, Args), list_to_atom(Task)). + rebar_core:process_command(rebar_state:command_args(State5, Args), Task). init_config() -> %% Initialize logging system @@ -177,10 +177,6 @@ init_config() -> %% Initialize vsn cache {PluginProviders, rebar_state:set(State1, vsn_cache, dict:new())}. -%% -%% Parse command line arguments using getopt and also filtering out any -%% key=value pairs. What's left is the list of commands to run -%% parse_args([]) -> parse_args(["help"]); parse_args([H | Rest]) when H =:= "-h" @@ -189,8 +185,8 @@ parse_args([H | Rest]) when H =:= "-h" parse_args([H | Rest]) when H =:= "-v" ; H =:= "--version" -> parse_args(["version" | Rest]); -parse_args([RawTask | RawRest]) -> - {RawTask, RawRest}. +parse_args([Task | RawRest]) -> + {list_to_atom(Task), RawRest}. set_options(State, {Options, NonOptArgs}) -> GlobalDefines = proplists:get_all_values(defines, Options), @@ -251,7 +247,6 @@ global_option_spec_list() -> [ %% {Name, ShortOpt, LongOpt, ArgSpec, HelpMsg} {help, $h, "help", undefined, "Print this help."}, - %{verbose, $v, "verbose", integer, "Verbosity level (-v, -vv)."}, {version, $V, "version", undefined, "Show version information."}, %{config, $C, "config", string, "Rebar config file to use."}, {task, undefined, undefined, string, "Task to run."} diff --git a/src/rebar_core.erl b/src/rebar_core.erl index b82bfc0..fa0e459 100644 --- a/src/rebar_core.erl +++ b/src/rebar_core.erl @@ -40,13 +40,15 @@ process_command(State, Command) -> not_found -> {error, io_lib:format("Command ~p not found", [Command])}; CommandProvider -> - Profile = providers:profile(CommandProvider), - State1 = rebar_state:apply_profiles(State, [Profile]), - Opts = providers:opts(CommandProvider)++rebar3:global_option_spec_list(), case Command of - do -> - do(TargetProviders, State1); + Command when Command =:= do + ; Command =:= as -> + do(TargetProviders, State); _ -> + Profile = providers:profile(CommandProvider), + State1 = rebar_state:apply_profiles(State, [Profile]), + Opts = providers:opts(CommandProvider)++rebar3:global_option_spec_list(), + case getopt:parse(Opts, rebar_state:command_args(State1)) of {ok, Args} -> State2 = rebar_state:command_parsed_args(State1, Args), diff --git a/src/rebar_prv_as.erl b/src/rebar_prv_as.erl new file mode 100644 index 0000000..1bd80cd --- /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 profile."}, + {desc, ""}, + {opts, [{profile, undefined, undefined, string, "Profile 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, " "), ",")]. diff --git a/src/rebar_prv_do.erl b/src/rebar_prv_do.erl index 10888eb..c2bbe2b 100644 --- a/src/rebar_prv_do.erl +++ b/src/rebar_prv_do.erl @@ -34,12 +34,12 @@ init(State) -> do(State) -> Tasks = args_to_tasks(rebar_state:command_args(State)), 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, State}, Tasks). + [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, State}, Tasks). -spec format_error(any()) -> iolist(). format_error(Reason) -> |