From e9dcaeee6dd9089f76d91f083d82c545de6f0720 Mon Sep 17 00:00:00 2001 From: Fred Hebert Date: Sat, 19 Mar 2016 13:34:01 -0400 Subject: Allow 'rebar3 pkgs ' to return only that app Unsure if this should be a final supported format or if we should support other ways to match instead. This is a demo to solve the issue hilighted in https://github.com/erlang/rebar3/pull/1072 --- src/rebar_prv_packages.erl | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/rebar_prv_packages.erl b/src/rebar_prv_packages.erl index 998320c..7217ab8 100644 --- a/src/rebar_prv_packages.erl +++ b/src/rebar_prv_packages.erl @@ -28,22 +28,19 @@ init(State) -> -spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}. do(State) -> rebar_packages:packages(State), - print_packages(), + case rebar_state:command_args(State) of + [Name] -> + print_packages(get_packages(iolist_to_binary(Name))); + _ -> + print_packages(sort_packages()) + end, {ok, State}. -spec format_error(any()) -> iolist(). format_error(load_registry_fail) -> "Failed to load package regsitry. Try running 'rebar3 update' to fix". -print_packages() -> - SortedPkgs = ets:foldl(fun({package_index_version, _}, Acc) -> - Acc; - ({Pkg, Vsns}, Acc) -> - orddict:store(Pkg, Vsns, Acc); - (_, Acc) -> - Acc - end, orddict:new(), ?PACKAGE_TABLE), - +print_packages(Pkgs) -> orddict:map(fun(Name, Vsns) -> SortedVsns = lists:sort(fun(A, B) -> ec_semver:lte(ec_semver:parse(A) @@ -51,7 +48,20 @@ print_packages() -> end, Vsns), VsnStr = join(SortedVsns, <<", ">>), ?CONSOLE("~s:~n Versions: ~s~n", [Name, VsnStr]) - end, SortedPkgs). + end, Pkgs). + +sort_packages() -> + ets:foldl(fun({package_index_version, _}, Acc) -> + Acc; + ({Pkg, Vsns}, Acc) -> + orddict:store(Pkg, Vsns, Acc); + (_, Acc) -> + Acc + end, orddict:new(), ?PACKAGE_TABLE). + +get_packages(Name) -> + ets:lookup(?PACKAGE_TABLE, Name). + -spec join([binary()], binary()) -> binary(). join([Bin], _Sep) -> -- cgit v1.1