summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFred Hebert <mononcqc@ferd.ca>2016-03-19 13:34:01 -0400
committerFred Hebert <mononcqc@ferd.ca>2016-03-19 13:34:01 -0400
commite9dcaeee6dd9089f76d91f083d82c545de6f0720 (patch)
tree3d15c96a0a7214023f03a906ebbe94cc685d1194
parent7d29b74a221ef082e4bbee496019c8f1612e8f0b (diff)
Allow 'rebar3 pkgs <app>' 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
-rw-r--r--src/rebar_prv_packages.erl32
1 files changed, 21 insertions, 11 deletions
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) ->