Skip to content
Browse files

Added agner:index/0 and "list" command for the command line utility

  • Loading branch information...
1 parent 0f111ec commit 453d4cc435c418f9260024349253555f1c3309f5 @yrashk yrashk committed Jan 25, 2011
Showing with 46 additions and 12 deletions.
  1. +1 −1 src/agner.app.src
  2. +14 −1 src/agner.erl
  3. +31 −10 src/agner_server.erl
View
2 src/agner.app.src
@@ -8,7 +8,7 @@
stdlib,
inets
]},
- {env, [{indeces, [{github, "agner"}]}]},
+ {env, [{indices, [{github, "agner"}]}]},
{mod, { agner_app, []}},
{env, []}
]}.
View
15 src/agner.erl
@@ -3,7 +3,7 @@
-export([start/0,stop/0]).
-export([main/1]).
%% API
--export([spec/1, spec/2]).
+-export([spec/1, spec/2, index/0]).
start() ->
inets:start(),
@@ -24,6 +24,14 @@ main(["spec"|Args]) ->
start(),
{ok, {Opts, _}} = getopt:parse(OptSpec, Args),
io:format("~p~n",[spec(proplists:get_value(package, Opts))]),
+ stop();
+
+main(["list"|Args]) ->
+ OptSpec = [
+ ],
+ start(),
+ {ok, {_Opts, _}} = getopt:parse(OptSpec, Args),
+ io:format("~p~n",[index()]),
stop().
%%%===================================================================
@@ -40,3 +48,8 @@ spec(Name, Version) when is_atom(Name) ->
spec(Name, Version) ->
gen_server:call(agner_server, {spec, Name, Version}).
+
+-spec index() -> list(agner_spec_name()).
+
+index() ->
+ gen_server:call(agner_server, index).
View
41 src/agner_server.erl
@@ -66,20 +66,20 @@ init([]) ->
%% @end
%%--------------------------------------------------------------------
-type agner_call_spec() :: {spec, agner_spec_name(), agner_spec_version()}.
+-type agner_call_index() :: index.
--spec handle_call(agner_call_spec(), gen_server_from(), gen_server_state()) ->
- gen_server_async_reply(agner_spec()).
+-spec handle_call(agner_call_spec(), gen_server_from(), gen_server_state()) -> gen_server_async_reply(agner_spec()) ;
+ (agner_call_index(), gen_server_from(), gen_server_state()) -> gen_server_async_reply(list(agner_spec_name())).
handle_call({spec, Name, Version}, From, #state{}=State) ->
spawn_link(fun () ->
- Indeces =
- case application:get_env(indeces) of
- {ok, Val} ->
- Val;
- undefined ->
- []
- end,
- handle_spec(Name, Version, From, Indeces)
+ handle_spec(Name, Version, From, indices())
+ end),
+ {noreply, State};
+
+handle_call(index, From, #state{}=State) ->
+ spawn_link(fun () ->
+ handle_index(From, indices())
end),
{noreply, State}.
@@ -163,5 +163,26 @@ handle_spec(Name, Version, From, [Mod0|Rest]) ->
gen_server:reply(From, Data)
end.
+-spec handle_index(gen_server_from(), list(tuple())) -> any().
+handle_index(From,[]) ->
+ gen_server:reply(From, {error, not_found});
+handle_index(From, [Mod0|Rest]) ->
+ Mod = index_module(Mod0),
+ case Mod:repositories() of
+ {error, not_found} ->
+ handle_index(From, Rest);
+ Repos ->
+ gen_server:reply(From, Repos)
+ end.
+
+
index_module({github, Account}) ->
{agner_github, Account}.
+
+indices() ->
+ case application:get_env(indices) of
+ {ok, Val} ->
+ Val;
+ undefined ->
+ []
+ end.

0 comments on commit 453d4cc

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