Skip to content
This repository
Browse code

Added 'spec --property' option

  • Loading branch information...
commit 61cb23f7c7a9caa83c606daf127b3312b6846230 1 parent 3490b57
Yurii Rashkovskii authored January 28, 2011
5  README.md
Source Rendered
@@ -77,7 +77,7 @@ SEARCH_TERM and only matching items are shown.
77 77
 This is an alias for `agner list -s`
78 78
 
79 79
     agner spec PACKAGE [-v/--version package_version] [-b/--browser] 
80  
-                       [-h/--homepage]
  80
+                       [-h/--homepage] [-p/--property PROPERTY]
81 81
 
82 82
 Will print a specification of a given package on stdout. If the
83 83
 optional version constraint is given (for example `agner spec gproc -v
@@ -90,6 +90,9 @@ file in its respective `.agner` repository.
90 90
 If `-h` or `--homepage` is present, it will also open browser with the package's
91 91
 homepage.
92 92
 
  93
+If `-p` or `--property` is supplied, agner will only render particular PROPERTY value
  94
+instead of a full specification (example: `agner spec -p rebar_compatible yaws`).
  95
+
93 96
     agner fetch PACKAGE [DESTDIR] [-v/--version package_version] [-c/--compile]
94 97
                                   [-a/--add-path]
95 98
 
10  src/agner_main.erl
@@ -25,7 +25,8 @@ arg_proplist() ->
25 25
 		{package, undefined, undefined, string, "Package name"},
26 26
 		{browser, $b, "browser", boolean, "Show specification in the browser"},
27 27
 		{homepage, $h, "homepage", boolean, "Show package homepage in the browser"},
28  
-		{version, $v, "version", {string, "@master"}, "Version"}
  28
+		{version, $v, "version", {string, "@master"}, "Version"},
  29
+        {property, $p, "property", string, "Particular property to render instead of a full spec"}
29 30
 	   ]}},
30 31
 	 {"versions",
31 32
 	  {versions,
@@ -133,7 +134,12 @@ handle_command(spec, Opts) ->
133 134
                 _ ->
134 135
                     ignore
135 136
             end,
136  
-            io:format("~p~n",[Spec])
  137
+            case proplists:get_value(property, Opts) of
  138
+                undefined ->
  139
+                    io:format("~p~n",[Spec]);
  140
+                Property ->
  141
+                    io:format("~s~n",[agner_spec:property_to_list(lists:keyfind(list_to_atom(Property), 1, Spec))])
  142
+            end
137 143
     end;
138 144
 
139 145
 handle_command(versions, Opts) ->
13  src/agner_spec.erl
... ...
@@ -1,7 +1,7 @@
1 1
 %% -*- Mode: Erlang; tab-width: 4 -*-
2 2
 -module(agner_spec).
3 3
 -include_lib("agner.hrl").
4  
--export([parse/1, list_to_version/2, version_to_list/1]).
  4
+-export([parse/1, list_to_version/2, version_to_list/1, property_to_list/1]).
5 5
 
6 6
 -type agner_spec_source() :: string().
7 7
 
@@ -45,3 +45,14 @@ version_to_list({flavour, Version}) ->
45 45
     "@" ++ Version;
46 46
 version_to_list({release, Version}) ->
47 47
     Version.
  48
+
  49
+-spec property_to_list(agner_spec_property()) -> string().
  50
+                               
  51
+property_to_list({_,V}) when is_list(V) ->
  52
+    io_lib:format("~s", [V]);
  53
+property_to_list(Prop) when is_tuple(Prop) ->
  54
+    io_lib:format("~p",[list_to_tuple(tl(tuple_to_list(Prop)))]);
  55
+property_to_list(undefined) ->
  56
+    "".
  57
+
  58
+    

0 notes on commit 61cb23f

Please sign in to comment.
Something went wrong with that request. Please try again.