diff options
author | Tristan Sloughter <t@crashfast.com> | 2015-06-21 21:24:50 -0500 |
---|---|---|
committer | Tristan Sloughter <t@crashfast.com> | 2015-06-21 21:24:50 -0500 |
commit | 9823ff12f048f0735fcb45574fbc66f30957b9bc (patch) | |
tree | 3ec0bbfea86768987aed69bf1a8157f756d58590 | |
parent | 6d3a107056833e4360baf0354774506a4ff2bec0 (diff) |
print sorted list of packages
-rw-r--r-- | src/rebar_prv_packages.erl | 23 |
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) -> |