summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFred Hebert <mononcqc@ferd.ca>2015-06-21 23:11:28 -0400
committerFred Hebert <mononcqc@ferd.ca>2015-06-21 23:11:28 -0400
commitc20ea1c924f4d9a36987b3a8a11b5749c7bbbe7a (patch)
tree3ec0bbfea86768987aed69bf1a8157f756d58590
parent11d7a07064d044f2383fc699d7180ea6830b1299 (diff)
parent9823ff12f048f0735fcb45574fbc66f30957b9bc (diff)
Merge pull request #533 from tsloughter/sorted_pkg_list
print sorted list of packages
-rw-r--r--src/rebar_prv_packages.erl23
1 files changed, 13 insertions, 10 deletions
diff --git a/src/rebar_prv_packages.erl b/src/rebar_prv_packages.erl
index 43e3080..8ba66de 100644
--- a/src/rebar_prv_packages.erl
+++ b/src/rebar_prv_packages.erl
@@ -27,9 +27,9 @@ init(State) ->
-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
do(State) ->
- case rebar_packages:registry(State) of
- {ok, Registry} ->
- print_packages(Registry),
+ case rebar_packages:get_packages(State) of
+ {Dict, _} ->
+ print_packages(Dict),
{ok, State};
error ->
?PRV_ERROR(load_registry_fail)
@@ -39,13 +39,16 @@ do(State) ->
format_error(load_registry_fail) ->
"Failed to load package regsitry. Try running 'rebar3 update' to fix".
-print_packages(Table) ->
- MS = ets:fun2ms(fun({Key, [Value]}) when is_binary(Key) -> {Key, Value} end),
- Pkgs = ets:select(Table, MS),
- lists:foreach(fun({Name, Vsns}) ->
- VsnStr = join(Vsns, <<", ">>),
- io:format("~s:~n Versions: ~s~n~n", [Name, VsnStr])
- end, Pkgs).
+print_packages(Dict) ->
+ Pkgs = lists:keysort(1, dict:fetch_keys(Dict)),
+ SortedPkgs = lists:foldl(fun({Pkg, Vsn}, Acc) ->
+ orddict:append_list(Pkg, [Vsn], Acc)
+ end, orddict:new(), Pkgs),
+
+ orddict:map(fun(Name, Vsns) ->
+ VsnStr = join(Vsns, <<", ">>),
+ io:format("~s:~n Versions: ~s~n~n", [Name, VsnStr])
+ end, SortedPkgs).
-spec join([binary()], binary()) -> binary().
join([Bin], _Sep) ->