Skip to content

Commit

Permalink
Added 'spec --property' option
Browse files Browse the repository at this point in the history
  • Loading branch information
yrashk committed Jan 28, 2011
1 parent 3490b57 commit 61cb23f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ SEARCH_TERM and only matching items are shown.
This is an alias for `agner list -s`

agner spec PACKAGE [-v/--version package_version] [-b/--browser]
[-h/--homepage]
[-h/--homepage] [-p/--property PROPERTY]

Will print a specification of a given package on stdout. If the
optional version constraint is given (for example `agner spec gproc -v
Expand All @@ -90,6 +90,9 @@ file in its respective `.agner` repository.
If `-h` or `--homepage` is present, it will also open browser with the package's
homepage.

If `-p` or `--property` is supplied, agner will only render particular PROPERTY value
instead of a full specification (example: `agner spec -p rebar_compatible yaws`).

agner fetch PACKAGE [DESTDIR] [-v/--version package_version] [-c/--compile]
[-a/--add-path]

Expand Down
10 changes: 8 additions & 2 deletions src/agner_main.erl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ arg_proplist() ->
{package, undefined, undefined, string, "Package name"},
{browser, $b, "browser", boolean, "Show specification in the browser"},
{homepage, $h, "homepage", boolean, "Show package homepage in the browser"},
{version, $v, "version", {string, "@master"}, "Version"}
{version, $v, "version", {string, "@master"}, "Version"},
{property, $p, "property", string, "Particular property to render instead of a full spec"}
]}},
{"versions",
{versions,
Expand Down Expand Up @@ -133,7 +134,12 @@ handle_command(spec, Opts) ->
_ ->
ignore
end,
io:format("~p~n",[Spec])
case proplists:get_value(property, Opts) of
undefined ->
io:format("~p~n",[Spec]);
Property ->
io:format("~s~n",[agner_spec:property_to_list(lists:keyfind(list_to_atom(Property), 1, Spec))])
end
end;

handle_command(versions, Opts) ->
Expand Down
13 changes: 12 additions & 1 deletion src/agner_spec.erl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
%% -*- Mode: Erlang; tab-width: 4 -*-
-module(agner_spec).
-include_lib("agner.hrl").
-export([parse/1, list_to_version/2, version_to_list/1]).
-export([parse/1, list_to_version/2, version_to_list/1, property_to_list/1]).

-type agner_spec_source() :: string().

Expand Down Expand Up @@ -45,3 +45,14 @@ version_to_list({flavour, Version}) ->
"@" ++ Version;
version_to_list({release, Version}) ->
Version.

-spec property_to_list(agner_spec_property()) -> string().

property_to_list({_,V}) when is_list(V) ->
io_lib:format("~s", [V]);
property_to_list(Prop) when is_tuple(Prop) ->
io_lib:format("~p",[list_to_tuple(tl(tuple_to_list(Prop)))]);
property_to_list(undefined) ->
"".


0 comments on commit 61cb23f

Please sign in to comment.