Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for all argument in upgrade #2629

Merged
merged 10 commits into from
Nov 26, 2021
30 changes: 16 additions & 14 deletions src/rebar_prv_upgrade.erl
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ init(State) ->
{desc, "Upgrade project dependencies. Mentioning no application "
"will upgrade all dependencies. To upgrade specific dependencies, "
"their names can be listed in the command."},
{opts, [
{opts, [{all, $a, "all", undefined, "Upgrade all dependencies."},
{package, undefined, undefined, string,
"List of packages to upgrade. If not specified, all dependencies are upgraded."}
"List of packages to upgrade."}
]}])),
{ok, State1}.

Expand All @@ -56,7 +56,6 @@ do(State) ->
end.

do_(State) ->
{Args, _} = rebar_state:command_parsed_args(State),
Locks = rebar_state:get(State, {locks, default}, []),
%% We have 3 sources of dependencies to upgrade from:
%% 1. the top-level rebar.config (in `deps', dep name is an atom)
Expand All @@ -81,8 +80,12 @@ do_(State) ->
ProfileDeps = rebar_state:get(State, {deps, default}, []),
Deps = [Dep || Dep <- TopDeps ++ ProfileDeps, % TopDeps > ProfileDeps
is_atom(Dep) orelse is_atom(element(1, Dep))],
Names = parse_names(rebar_utils:to_binary(proplists:get_value(package, Args, <<"">>)), Locks),

Names = case handle_args(State) of
{false, undefined} -> throw(?PRV_ERROR(no_arg));
{true, _} -> [Name || {Name, _, 0} <- Locks];
{false, Packages} -> Bin = rebar_utils:to_binary(Packages),
lists:usort(re:split(Bin, <<" *, *">>, [trim, unicode]))
joshrotenberg marked this conversation as resolved.
Show resolved Hide resolved
end,
DepsDict = deps_dict(rebar_state:all_deps(State)),
AltDeps = find_non_default_deps(Deps, State),
FilteredNames = cull_default_names_if_profiles(Names, Deps, State),
Expand Down Expand Up @@ -127,9 +130,17 @@ format_error({transitive_dependency, Name}) ->
format_error({checkout_dependency, Name}) ->
io_lib:format("Dependency ~ts is a checkout dependency under _checkouts/ and checkouts cannot be upgraded.",
[Name]);
format_error(no_arg) ->
"Specify a list of dependencies to unlock, or --all to unlock them all";
format_error(Reason) ->
io_lib:format("~p", [Reason]).

handle_args(State) ->
{Args, _} = rebar_state:command_parsed_args(State),
All = proplists:get_value(all, Args, false),
Package = proplists:get_value(package, Args),
{All, Package}.

%% fetch updates for package deps that have been unlocked for upgrade
update_pkg_deps([], _, _) ->
ok;
Expand Down Expand Up @@ -160,15 +171,6 @@ update_package(Name, RepoConfig, State) ->
ok
end.

parse_names(Bin, Locks) ->
case lists:usort(re:split(Bin, <<" *, *">>, [trim, unicode])) of
%% Nothing submitted, use *all* apps
[<<"">>] -> [Name || {Name, _, 0} <- Locks];
[] -> [Name || {Name, _, 0} <- Locks];
%% Regular options
Other -> Other
end.

%% Find alternative deps in non-default profiles since they may
%% need to be passed through (they are never locked)
find_non_default_deps(Deps, State) ->
Expand Down