summaryrefslogtreecommitdiff
path: root/src/rebar_core.erl
diff options
context:
space:
mode:
authoromarkj <omarkj@gmail.com>2014-11-03 13:58:58 -0800
committeromarkj <omarkj@gmail.com>2014-11-03 13:58:58 -0800
commita1d030c9649526422f58e0fb5dae9d33564b395a (patch)
treefeb95f0fec3421ed876e1802584430e18e29f73f /src/rebar_core.erl
parent58f4019fa62a73e335967870f6605182d7386830 (diff)
parenta3ec3a3424dd47e9687d0d2960ef2d3cba6a8f5c (diff)
add help
Diffstat (limited to 'src/rebar_core.erl')
-rw-r--r--src/rebar_core.erl58
1 files changed, 43 insertions, 15 deletions
diff --git a/src/rebar_core.erl b/src/rebar_core.erl
index cb021e3..16d8f07 100644
--- a/src/rebar_core.erl
+++ b/src/rebar_core.erl
@@ -26,33 +26,61 @@
%% -------------------------------------------------------------------
-module(rebar_core).
--export([process_command/2]).
+-export([process_command/2
+ ,update_code_path/1]).
-include("rebar.hrl").
+-spec process_command(rebar_state:t(), atom()) -> {ok, rebar_state:t()} | {error, string()}.
process_command(State, Command) ->
+ %% ? rebar_prv_install_deps:setup_env(State),
+ Providers = rebar_state:providers(State),
+ TargetProviders = providers:get_target_providers(Command, Providers),
+ case providers:get_provider(Command, Providers) of
+ not_found ->
+ {error, io_lib:format("Command ~p not found", [Command])};
+ CommandProvider ->
+ Opts = providers:opts(CommandProvider)++rebar3:global_option_spec_list(),
+ case Command of
+ do ->
+ do(TargetProviders, State);
+ _ ->
+ case getopt:parse(Opts, rebar_state:command_args(State)) of
+ {ok, Args} ->
+ State2 = rebar_state:command_parsed_args(State, Args),
+ do(TargetProviders, State2);
+ {error, {invalid_option, Option}} ->
+ {error, io_lib:format("Invalid option ~s on task ~p", [Option, Command])}
+ end
+ end
+ end.
+
+-spec do([atom()], rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
+do([], State) ->
+ {ok, State};
+do([ProviderName | Rest], State) ->
+ Provider = providers:get_provider(ProviderName
+ ,rebar_state:providers(State)),
+ case providers:do(Provider, State) of
+ {ok, State1} ->
+ do(Rest, State1);
+ {error, Error} ->
+ {error, Error}
+ end.
+
+update_code_path(State) ->
true = rebar_utils:expand_code_path(),
LibDirs = rebar_state:get(State, lib_dirs, ?DEFAULT_LIB_DIRS),
- DepsDir = rebar_state:get(State, deps_dir, ?DEFAULT_DEPS_DIRS),
- _UpdatedCodePaths = update_code_path([DepsDir | LibDirs]),
- rebar_prv_install_deps:setup_env(State),
-
- TargetProviders = rebar_provider:get_target_providers(Command, State),
+ DepsDir = rebar_state:get(State, deps_dir, ?DEFAULT_DEPS_DIR),
+ PluginsDir = rebar_state:get(State, plugins_dir, ?DEFAULT_PLUGINS_DIR),
+ _UpdatedCodePaths = update_code_path_([DepsDir, PluginsDir | LibDirs]).
- lists:foldl(fun(TargetProvider, Conf) ->
- Provider = rebar_provider:get_provider(TargetProvider
- ,rebar_state:providers(Conf)),
- {ok, Conf1} = rebar_provider:do(Provider, Conf),
- Conf1
- end, State, TargetProviders).
%% ===================================================================
%% Internal functions
%% ===================================================================
-update_code_path([]) ->
- no_change;
-update_code_path(Paths) ->
+update_code_path_(Paths) ->
LibPaths = expand_lib_dirs(Paths, rebar_utils:get_cwd(), []),
ok = code:add_pathsa(LibPaths),
%% track just the paths we added, so we can remove them without