summaryrefslogtreecommitdiff
path: root/src/rebar_prv_plugins_upgrade.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/rebar_prv_plugins_upgrade.erl')
-rw-r--r--src/rebar_prv_plugins_upgrade.erl41
1 files changed, 26 insertions, 15 deletions
diff --git a/src/rebar_prv_plugins_upgrade.erl b/src/rebar_prv_plugins_upgrade.erl
index fbd8365..02c185f 100644
--- a/src/rebar_prv_plugins_upgrade.erl
+++ b/src/rebar_prv_plugins_upgrade.erl
@@ -33,10 +33,16 @@ init(State) ->
-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
do(State) ->
{Args, _} = rebar_state:command_parsed_args(State),
- Plugin = proplists:get_value(plugin, Args, <<"">>),
- upgrade(Plugin, State).
+ case proplists:get_value(plugin, Args, none) of
+ none ->
+ ?PRV_ERROR(no_plugin_arg);
+ Plugin ->
+ upgrade(Plugin, State)
+ end.
-spec format_error(any()) -> iolist().
+format_error(no_plugin_arg) ->
+ io_lib:format("Must give an installed plugin to upgrade as an argument", []);
format_error({not_found, Plugin}) ->
io_lib:format("Plugin to upgrade not found: ~s", [Plugin]);
format_error(Reason) ->
@@ -44,25 +50,19 @@ format_error(Reason) ->
upgrade(Plugin, State) ->
Profiles = rebar_state:current_profiles(State),
- Dep = ec_lists:search(fun(Profile) ->
- Plugins = rebar_state:get(State, {plugins, Profile}, []),
- case find(list_to_atom(Plugin), Plugins) of
- false ->
- not_found;
- P ->
- {ok, P}
- end
- end, Profiles),
+ case find_plugin(Plugin, Profiles, State) of
+ not_found ->
+ Dep = find_plugin(Plugin, [global], State);
+ Dep ->
+ Dep
+ end,
case Dep of
not_found ->
?PRV_ERROR({not_found, Plugin});
{ok, P, Profile} ->
State1 = rebar_state:set(State, deps_dir, ?DEFAULT_PLUGINS_DIR),
- {ok, Apps, _State2} = rebar_prv_install_deps:handle_deps(Profile
- ,State1
- ,[P]
- ,true),
+ {Apps, _State2} = rebar_prv_install_deps:handle_deps_as_profile(Profile, State1, [P], true),
{no_cycle, Sorted} = rebar_prv_install_deps:find_cycles(Apps),
ToBuild = rebar_prv_install_deps:cull_compile(Sorted, []),
@@ -76,6 +76,17 @@ upgrade(Plugin, State) ->
{ok, State}
end.
+find_plugin(Plugin, Profiles, State) ->
+ ec_lists:search(fun(Profile) ->
+ Plugins = rebar_state:get(State, {plugins, Profile}, []),
+ case find(list_to_atom(Plugin), Plugins) of
+ false ->
+ not_found;
+ P ->
+ {ok, P}
+ end
+ end, Profiles).
+
find(_Plugin, []) ->
false;
find(Plugin, [Plugin | _Plugins]) ->