From c2209785f96b8de2fd3a77017a038711be2d6cc0 Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Thu, 25 Jun 2015 21:17:05 -0500 Subject: add error message when no plugin is passed to plugins upgrade --- src/rebar_prv_plugins_upgrade.erl | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/rebar_prv_plugins_upgrade.erl b/src/rebar_prv_plugins_upgrade.erl index fbd8365..c80dffc 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) -> -- cgit v1.1 From b830c65ef0c66875dc1b525186542d3609cfe452 Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Thu, 25 Jun 2015 21:32:29 -0500 Subject: check global for plugin if not found in local profiles --- src/rebar_prv_plugins_upgrade.erl | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/rebar_prv_plugins_upgrade.erl b/src/rebar_prv_plugins_upgrade.erl index c80dffc..5ccd054 100644 --- a/src/rebar_prv_plugins_upgrade.erl +++ b/src/rebar_prv_plugins_upgrade.erl @@ -50,15 +50,12 @@ 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 -> @@ -82,6 +79,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]) -> -- cgit v1.1