Permalink
Browse files

Added 'spec --property' option

  • Loading branch information...
1 parent 3490b57 commit 61cb23f7c7a9caa83c606daf127b3312b6846230 @yrashk yrashk committed Jan 28, 2011
Showing with 24 additions and 4 deletions.
  1. +4 −1 README.md
  2. +8 −2 src/agner_main.erl
  3. +12 −1 src/agner_spec.erl
View
@@ -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
@@ -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]
View
@@ -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,
@@ -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) ->
View
@@ -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().
@@ -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.