diff options
Diffstat (limited to 'src/rebar_prv_packages.erl')
-rw-r--r-- | src/rebar_prv_packages.erl | 33 |
1 files changed, 14 insertions, 19 deletions
diff --git a/src/rebar_prv_packages.erl b/src/rebar_prv_packages.erl index 8ba9e92..c7c0d50 100644 --- a/src/rebar_prv_packages.erl +++ b/src/rebar_prv_packages.erl @@ -7,6 +7,8 @@ format_error/1]). -include("rebar.hrl"). +-include_lib("stdlib/include/ms_transform.hrl"). +-include_lib("providers/include/providers.hrl"). -define(PROVIDER, pkgs). -define(DEPS, []). @@ -25,33 +27,26 @@ init(State) -> -spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}. do(State) -> - {Packages, _Graph} = rebar_packages:get_packages(State), - print_packages(Packages), - {ok, State}. + case rebar_packages:registry(State) of + {ok, Registry} -> + print_packages(Registry), + {ok, State}; + error -> + ?PRV_ERROR(load_registry_fail) + end. -spec format_error(any()) -> iolist(). -format_error(Reason) -> - io_lib:format("~p", [Reason]). +format_error(load_registry_fail) -> + "Failed to load package regsitry. Try running 'rebar3 update' to fix". -print_packages(Packages) -> - Keys = lists:keysort(1, dict:fetch_keys(Packages)), - Pkgs = merge(Keys), +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). --spec merge([{binary(), binary()}]) -> [{binary(), [binary()]}]. -merge(List) -> - merge([], List). - -merge(List, []) -> - List; -merge([{Key, Values} | T], [{Key, Value} | Rest]) -> - merge([{Key, [Value | Values]} | T], Rest); -merge(List, [{Key, Value} | Rest]) -> - merge([{Key, [Value]} | List], Rest). - -spec join([binary()], binary()) -> binary(). join([Bin], _Sep) -> <<Bin/binary>>; |