Permalink
Browse files

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

… specifying local spec file)
  • Loading branch information...
1 parent c89b6cf commit d87929fd574e0d5966d17b8a220d413064ba650c @yrashk yrashk committed Jan 29, 2011
Showing with 55 additions and 19 deletions.
  1. +9 −0 README.md
  2. +25 −6 src/agner_main.erl
  3. +21 −13 src/agner_server.erl
View
9 README.md
@@ -78,6 +78,7 @@ This is an alias for `agner list -s`
agner spec PACKAGE [-v/--version VERSION] [-b/--browser]
[-h/--homepage] [-p/--property PROPERTY]
+ [-s/--spec-file SPECFILE]
Will print a specification of a given package on stdout. If the
optional version constraint is given (for example `agner spec gproc -v
@@ -93,8 +94,13 @@ 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`).
+Option `-s` or `--spec-file` is primarily intended for package maintainers. This way they can specify their
+local `agner.config` files to test their package.
+
+
agner fetch PACKAGE [DESTDIR] [-v/--version VERSION] [-b/--build]
[-a/--add-path] [-i/--install]
+ [-s/--spec-file SPECFILE]
Fetch a given `PACKAGE` to either the current directory or,
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
install this package. Please note that in most cases you should also specify `--build`/`-b` in order for
installation to make sense.
+Option `-s` or `--spec-file` is primarily intended for package maintainers. This way they can specify their
+local `agner.config` files to test their package.
+
agner install PACKAGE [-v/--version VERSION]
Alias for `agner fetch --build --install PACKAGE /tmp/<uniq_filename>`. A typical example would be `agner install rebar`
View
31 src/agner_main.erl
@@ -28,7 +28,8 @@ arg_proplist() ->
{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"},
- {property, $p, "property", string, "Particular property to render instead of a full spec"}
+ {property, $p, "property", string, "Particular property to render instead of a full spec"},
+ {spec, $s, "spec-file", string, "Use local specification file"}
]}},
{"versions",
{versions,
@@ -61,14 +62,16 @@ arg_proplist() ->
{version, $v, "version", {string, "@master"}, "Version"},
{build, $b, "build", {boolean, false}, "Build fetched package"},
{addpath, $a, "add-path", {boolean, false}, "Add path to compiled package to .erlang"},
- {install, $i, "install", {boolean, false}, "Install package (if install_command is available)"}
+ {install, $i, "install", {boolean, false}, "Install package (if install_command is available)"},
+ {spec, $s, "spec-file", string, "Use local specification file"}
]}},
{"install",
{install,
"Install a package",
[
{package, undefined, undefined, string, "Package name"},
- {version, $v, "version", {string, "@master"}, "Version"}
+ {version, $v, "version", {string, "@master"}, "Version"},
+ {spec, $s, "spec-file", string, "Use local specification file"}
]}},
{"verify",
{verify,
@@ -143,7 +146,14 @@ handle_command(spec, Opts) ->
_ ->
ignore
end,
- Spec = agner:spec(Package,Version),
+ Spec =
+ case proplists:get_value(spec, Opts) of
+ undefined ->
+ agner:spec(Package, Version);
+ File ->
+ {ok, T} = file:consult(File),
+ T
+ end,
case proplists:get_value(homepage, Opts) of
true ->
agner_utils:launch_browser(proplists:get_value(homepage, Spec, "http://google.com/?q=" ++ Package));
@@ -228,9 +238,18 @@ handle_command(fetch, Opts) ->
Package ->
Version = proplists:get_value(version, Opts),
Directory = filename:absname(proplists:get_value(directory, Opts, Package)),
- io:format("~p~n",[agner:fetch(Package,Version,
+ Spec =
+ case proplists:get_value(spec, Opts) of
+ undefined ->
+ agner:spec(Package, Version);
+ File ->
+ {ok, T} = file:consult(File),
+ T
+ end,
+
+ io:format("~p~n",[agner:fetch(Spec,Version,
Directory)]),
- Spec = agner:spec(Package, Version),
+
case proplists:get_value(caveats, Spec) of
undefined ->
ignore;
View
34 src/agner_server.erl
@@ -58,10 +58,11 @@ index() ->
%% @doc Fetch a package/project to a directory
%% @end
--spec fetch(agner_spec_name(), agner_spec_version(), directory()) -> ok | not_found_error().
+-spec fetch(agner_spec_name(), agner_spec_version(), directory()) -> ok | not_found_error();
+ (agner_spec(), any(), directory()) -> ok | not_found_error().
-fetch(Name, Version, Directory) ->
- gen_server:call(?SERVER, {fetch, Name, Version, Directory}, infinity).
+fetch(NameOrSpec, Version, Directory) ->
+ gen_server:call(?SERVER, {fetch, NameOrSpec, Version, Directory}, infinity).
%% @doc Ask for the versions of a given package, Name
%% @end
@@ -109,7 +110,7 @@ init([]) ->
-type agner_call_spec() :: {spec, agner_spec_name(), agner_spec_version()}.
-type agner_call_spec_url() :: {spec_url, agner_spec_name(), agner_spec_version()}.
-type agner_call_index() :: index.
--type agner_call_fetch() :: {fetch, agner_spec_name(), agner_spec_version(), directory()}.
+-type agner_call_fetch() :: {fetch, agner_spec_name() | agner_spec(), agner_spec_version(), directory()}.
-type agner_call_versions() :: {versions, agner_spec_name()}.
-type agner_internal_call_pushed_at_updates() :: {pushed_at_updates, list({agner_spec_name(), string()})}.
-type agner_internal_call_pushed_at() :: {pushed_at, agner_spec_name()}.
@@ -141,9 +142,9 @@ handle_call(index, From, #state{}=State) ->
end),
{noreply, State};
-handle_call({fetch, Name, Version, Directory}, From, #state{}=State) ->
+handle_call({fetch, NameOrSpec, Version, Directory}, From, #state{}=State) ->
spawn_link(fun () ->
- handle_fetch(Name, Version, Directory, From)
+ handle_fetch(NameOrSpec, Version, Directory, From)
end),
{noreply, State};
@@ -280,13 +281,20 @@ handle_index(From, Acc, [Mod0|Rest]) ->
handle_index(From, lists:map(fun (Repo) -> indexize(Mod0, Repo) end, Repos) ++ Acc, Rest)
end.
--spec handle_fetch(agner_spec_name(), agner_spec_version(), directory(), gen_server_from()) -> any().
-handle_fetch(Name, Version, Directory, From) ->
- case agner:spec(Name, Version) of
- {error, _} = Error ->
- gen_server:reply(From, Error);
- Spec ->
- URL = proplists:get_value(url, Spec),
+-spec handle_fetch(agner_spec_name() | agner_spec(), agner_spec_version(), directory(), gen_server_from()) -> any().
+handle_fetch(NameOrSpec, Version, Directory, From) ->
+ case io_lib:printable_list(NameOrSpec) of
+ true ->
+ case agner:spec(NameOrSpec, Version) of
+ {error, _} = Error ->
+ gen_server:reply(From, Error);
+ Spec ->
+ URL = proplists:get_value(url, Spec),
+ agner_download:fetch(URL, Directory),
+ gen_server:reply(From, ok)
+ end;
+ false -> %% it is a spec
+ URL = proplists:get_value(url, NameOrSpec),
agner_download:fetch(URL, Directory),
gen_server:reply(From, ok)
end.

0 comments on commit d87929f

Please sign in to comment.