Skip to content
This repository
Browse code

Added -s/--spec-file option to fetch, spec & install commands (allows…

… specifying local spec file)
  • Loading branch information...
commit d87929fd574e0d5966d17b8a220d413064ba650c 1 parent c89b6cf
Yurii Rashkovskii authored January 28, 2011
9  README.md
Source Rendered
@@ -78,6 +78,7 @@ This is an alias for `agner list -s`
78 78
 
79 79
     agner spec PACKAGE [-v/--version VERSION] [-b/--browser] 
80 80
                        [-h/--homepage] [-p/--property PROPERTY]
  81
+                       [-s/--spec-file SPECFILE]
81 82
 
82 83
 Will print a specification of a given package on stdout. If the
83 84
 optional version constraint is given (for example `agner spec gproc -v
@@ -93,8 +94,13 @@ homepage.
93 94
 If `-p` or `--property` is supplied, agner will only render particular PROPERTY value
94 95
 instead of a full specification (example: `agner spec -p rebar_compatible yaws`).
95 96
 
  97
+Option `-s` or `--spec-file` is primarily intended for package maintainers. This way they can specify their
  98
+local `agner.config` files to test their package.
  99
+
  100
+
96 101
     agner fetch PACKAGE [DESTDIR] [-v/--version VERSION] [-b/--build]
97 102
                                   [-a/--add-path] [-i/--install]
  103
+                                  [-s/--spec-file SPECFILE]
98 104
 
99 105
 Fetch a given `PACKAGE` to either the current directory or,
100 106
 optionally, to the `DESTDIR` directory. The version constraint is as
@@ -109,6 +115,9 @@ If `-i` or `--install` is supplied and package has `install_command` property de
109 115
 install this package. Please note that in most cases you should also specify `--build`/`-b` in order for
110 116
 installation to make sense.
111 117
 
  118
+Option `-s` or `--spec-file` is primarily intended for package maintainers. This way they can specify their
  119
+local `agner.config` files to test their package.
  120
+
112 121
     agner install PACKAGE [-v/--version VERSION]
113 122
 
114 123
 Alias for `agner fetch --build --install PACKAGE /tmp/<uniq_filename>`. A typical example would be `agner install rebar`
31  src/agner_main.erl
@@ -28,7 +28,8 @@ arg_proplist() ->
28 28
 		{browser, $b, "browser", boolean, "Show specification in the browser"},
29 29
 		{homepage, $h, "homepage", boolean, "Show package homepage in the browser"},
30 30
 		{version, $v, "version", {string, "@master"}, "Version"},
31  
-        {property, $p, "property", string, "Particular property to render instead of a full spec"}
  31
+        {property, $p, "property", string, "Particular property to render instead of a full spec"},
  32
+        {spec, $s, "spec-file", string, "Use local specification file"}
32 33
 	   ]}},
33 34
 	 {"versions",
34 35
 	  {versions,
@@ -61,14 +62,16 @@ arg_proplist() ->
61 62
 		{version, $v, "version", {string, "@master"}, "Version"},
62 63
         {build, $b, "build", {boolean, false}, "Build fetched package"},
63 64
         {addpath, $a, "add-path", {boolean, false}, "Add path to compiled package to .erlang"},
64  
-        {install, $i, "install", {boolean, false}, "Install package (if install_command is available)"}
  65
+        {install, $i, "install", {boolean, false}, "Install package (if install_command is available)"},
  66
+        {spec, $s, "spec-file", string, "Use local specification file"}
65 67
 	   ]}},
66 68
      {"install",
67 69
       {install,
68 70
        "Install a package",
69 71
 	   [
70 72
 		{package, undefined, undefined, string, "Package name"},
71  
-		{version, $v, "version", {string, "@master"}, "Version"}
  73
+		{version, $v, "version", {string, "@master"}, "Version"},
  74
+        {spec, $s, "spec-file", string, "Use local specification file"}
72 75
 	   ]}},
73 76
 	 {"verify",
74 77
 	  {verify,
@@ -143,7 +146,14 @@ handle_command(spec, Opts) ->
143 146
                 _ ->
144 147
                     ignore
145 148
             end,
146  
-            Spec = agner:spec(Package,Version),
  149
+            Spec = 
  150
+                case proplists:get_value(spec, Opts) of
  151
+                    undefined ->
  152
+                        agner:spec(Package, Version);
  153
+                    File ->
  154
+                        {ok, T} = file:consult(File),
  155
+                        T
  156
+                end,
147 157
             case proplists:get_value(homepage, Opts) of
148 158
                 true ->
149 159
                     agner_utils:launch_browser(proplists:get_value(homepage, Spec, "http://google.com/?q=" ++ Package));
@@ -228,9 +238,18 @@ handle_command(fetch, Opts) ->
228 238
         Package ->
229 239
             Version = proplists:get_value(version, Opts),
230 240
             Directory = filename:absname(proplists:get_value(directory, Opts, Package)),
231  
-            io:format("~p~n",[agner:fetch(Package,Version,
  241
+            Spec = 
  242
+                case proplists:get_value(spec, Opts) of
  243
+                    undefined ->
  244
+                        agner:spec(Package, Version);
  245
+                    File ->
  246
+                        {ok, T} = file:consult(File),
  247
+                        T
  248
+                end,
  249
+
  250
+            io:format("~p~n",[agner:fetch(Spec,Version,
232 251
                                     Directory)]),
233  
-            Spec = agner:spec(Package, Version),
  252
+                           
234 253
             case proplists:get_value(caveats, Spec) of
235 254
                 undefined ->
236 255
                     ignore;
34  src/agner_server.erl
@@ -58,10 +58,11 @@ index() ->
58 58
 
59 59
 %% @doc Fetch a package/project to a directory
60 60
 %% @end
61  
--spec fetch(agner_spec_name(), agner_spec_version(), directory()) -> ok | not_found_error().
  61
+-spec fetch(agner_spec_name(), agner_spec_version(), directory()) -> ok | not_found_error();
  62
+           (agner_spec(), any(), directory()) -> ok | not_found_error().
62 63
                    
63  
-fetch(Name, Version, Directory) ->
64  
-        gen_server:call(?SERVER, {fetch, Name, Version, Directory}, infinity).
  64
+fetch(NameOrSpec, Version, Directory) ->
  65
+        gen_server:call(?SERVER, {fetch, NameOrSpec, Version, Directory}, infinity).
65 66
 
66 67
 %% @doc Ask for the versions of a given package, Name
67 68
 %% @end
@@ -109,7 +110,7 @@ init([]) ->
109 110
 -type agner_call_spec() :: {spec, agner_spec_name(), agner_spec_version()}.
110 111
 -type agner_call_spec_url() :: {spec_url, agner_spec_name(), agner_spec_version()}.
111 112
 -type agner_call_index() :: index.
112  
--type agner_call_fetch() :: {fetch, agner_spec_name(), agner_spec_version(), directory()}.
  113
+-type agner_call_fetch() :: {fetch, agner_spec_name() | agner_spec(), agner_spec_version(), directory()}.
113 114
 -type agner_call_versions() :: {versions, agner_spec_name()}.
114 115
 -type agner_internal_call_pushed_at_updates() :: {pushed_at_updates, list({agner_spec_name(), string()})}.
115 116
 -type agner_internal_call_pushed_at() :: {pushed_at, agner_spec_name()}.
@@ -141,9 +142,9 @@ handle_call(index, From, #state{}=State) ->
141 142
 			   end),
142 143
 	{noreply, State};
143 144
 
144  
-handle_call({fetch, Name, Version, Directory}, From, #state{}=State) ->
  145
+handle_call({fetch, NameOrSpec, Version, Directory}, From, #state{}=State) ->
145 146
 	spawn_link(fun () ->
146  
-					   handle_fetch(Name, Version, Directory, From)
  147
+					   handle_fetch(NameOrSpec, Version, Directory, From)
147 148
 			   end),
148 149
 	{noreply, State};
149 150
 
@@ -280,13 +281,20 @@ handle_index(From, Acc, [Mod0|Rest]) ->
280 281
             handle_index(From, lists:map(fun (Repo) -> indexize(Mod0, Repo) end, Repos) ++ Acc, Rest)
281 282
 	end.
282 283
 
283  
--spec handle_fetch(agner_spec_name(), agner_spec_version(), directory(), gen_server_from()) -> any().
284  
-handle_fetch(Name, Version, Directory, From) ->
285  
-    case agner:spec(Name, Version) of
286  
-        {error, _} = Error ->
287  
-            gen_server:reply(From, Error);
288  
-        Spec ->
289  
-            URL = proplists:get_value(url, Spec),
  284
+-spec handle_fetch(agner_spec_name() | agner_spec(), agner_spec_version(), directory(), gen_server_from()) -> any().
  285
+handle_fetch(NameOrSpec, Version, Directory, From) ->
  286
+    case io_lib:printable_list(NameOrSpec) of
  287
+        true ->
  288
+            case agner:spec(NameOrSpec, Version) of
  289
+                {error, _} = Error ->
  290
+                    gen_server:reply(From, Error);
  291
+                Spec ->
  292
+                    URL = proplists:get_value(url, Spec),
  293
+                    agner_download:fetch(URL, Directory),
  294
+                    gen_server:reply(From, ok)
  295
+            end;
  296
+        false -> %% it is a spec
  297
+            URL = proplists:get_value(url, NameOrSpec),
290 298
             agner_download:fetch(URL, Directory),
291 299
             gen_server:reply(From, ok)
292 300
     end.

0 notes on commit d87929f

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