Permalink
Browse files

Extracted spec defaults

All spec defaults are now available in (unexported) agner_spec:defaults/1.
Added agner_spec:normalize/1 which currently adds defaults to the given spec (more is like to come later)
  • Loading branch information...
yrashk committed Feb 13, 2011
1 parent 0a51db4 commit c091f2e6cc697e1159555e906fa2cb575c5ee135
Showing with 42 additions and 26 deletions.
  1. +4 −4 src/agner_fetch.erl
  2. +19 −17 src/agner_github.erl
  3. +2 −2 src/agner_main.erl
  4. +17 −3 src/agner_spec.erl
View
@@ -383,10 +383,10 @@ requires(Spec) ->
true;
(A,B) ->
A =< B
- end, proplists:get_value(requires, Spec, [])).
+ end, proplists:get_value(requires, Spec)).
deps_dir(Spec, Directory) ->
- filename:join(Directory, proplists:get_value(deps_dir, Spec, "deps")).
+ filename:join(Directory, proplists:get_value(deps_dir, Spec)).
unsatisfied_requirements(Spec) ->
lists:filter(fun ("agner") ->
@@ -425,7 +425,7 @@ rebar(#opts_rec{ spec = {spec, Spec}, directory = Directory }) ->
{ok, Cwd} = file:get_cwd(),
file:set_cwd(Directory),
rebar_config:set_global(shutdown_agner, false), %% prevents rebar from shutting down agner
- RebarCommands = proplists:get_value(rebar_commands, Spec, ["get-deps","compile"]),
+ RebarCommands = proplists:get_value(rebar_commands, Spec),
rebar:main(RebarCommands),
file:set_cwd(Cwd);
_ ->
@@ -438,7 +438,7 @@ build_command(#opts_rec{ spec = {spec, Spec}, directory = Directory, quiet = Qui
case proplists:get_value(build_command, Spec) of
undefined ->
- case proplists:get_value(rebar_compatible, Spec, false) of
+ case proplists:get_value(rebar_compatible, Spec) of
false ->
io:format("WARNING: No build_command specified, can't build this package~n");
_ ->
View
@@ -175,23 +175,25 @@ spec(Name, Version) ->
end.
spec_1(RepoServer, AtFilename) ->
- case file:read_file_info(AtFilename) of
- {error, enoent} ->
- case agner_repo_server:clone(RepoServer, fun (Name) -> "git://github.com/" ++ proper_repo_name(Name) ++ ".git" end) of
- ok ->
- Config = agner_repo_server:file(RepoServer, "agner.config"),
- {ok, S} = file:consult(Config),
- {ok, _} = file:copy(Config, AtFilename),
- {ok, #file_info{mode = Mode}} = file:read_file_info(AtFilename),
- file:change_mode(AtFilename, Mode bor 8#00444),
- S;
- _ ->
- {error, not_found}
- end;
- {ok, _} ->
- {ok, S} = file:consult(AtFilename),
- S
- end.
+ Spec =
+ case file:read_file_info(AtFilename) of
+ {error, enoent} ->
+ case agner_repo_server:clone(RepoServer, fun (Name) -> "git://github.com/" ++ proper_repo_name(Name) ++ ".git" end) of
+ ok ->
+ Config = agner_repo_server:file(RepoServer, "agner.config"),
+ {ok, S} = file:consult(Config),
+ {ok, _} = file:copy(Config, AtFilename),
+ {ok, #file_info{mode = Mode}} = file:read_file_info(AtFilename),
+ file:change_mode(AtFilename, Mode bor 8#00444),
+ S;
+ _ ->
+ {error, not_found}
+ end;
+ {ok, _} ->
+ {ok, S} = file:consult(AtFilename),
+ S
+ end,
+ agner_spec:normalize(Spec).
spec_url(Name, SHA1) ->
"https://github.com/" ++ proper_repo_name(Name) ++ "/blob/" ++ SHA1 ++ "/agner.config".
View
@@ -219,7 +219,7 @@ handle_command(spec, Opts) ->
_ ->
case proplists:get_value(homepage, Opts) of
true ->
- agner_utils:launch_browser(proplists:get_value(homepage, Spec, "http://google.com/#q=" ++ Package));
+ agner_utils:launch_browser(proplists:get_value(homepage, Spec));
_ ->
ignore
end,
@@ -261,7 +261,7 @@ handle_command(list, Opts) ->
Properties = lists:map(fun list_to_atom/1, string:tokens(proplists:get_value(properties, Opts,""),",")),
lists:foreach(fun (Name) ->
Spec = agner:spec(Name),
- Searchable = string:to_lower(lists:flatten([Name,proplists:get_value(description,Spec,[])|proplists:get_value(keywords,Spec,[])])),
+ Searchable = string:to_lower(lists:flatten([Name,proplists:get_value(description,Spec)|proplists:get_value(keywords,Spec)])),
Show =
case Search of
undefined ->
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, property_to_list/1, version_compare/3]).
+-export([parse/1, list_to_version/2, version_to_list/1, property_to_list/1, version_compare/3, normalize/1]).
-type agner_spec_source() :: string().
@@ -80,6 +80,20 @@ version_components(Version) ->
end
end, Components)).
-
-
+
+-spec normalize(agner_spec()) -> agner_spec().
+
+normalize(Spec) ->
+ lists:ukeysort(1,Spec ++ defaults(proplists:get_value(name, Spec, ""))).
+
+-spec defaults(agner_package_name()) -> agner_spec().
+
+defaults(Package) ->
+ [{rebar_compatible, false},
+ {requires, []},
+ {deps_dir, "deps"},
+ {rebar_commands, ["get-deps","compile"]},
+ {homepage, "http://google.com/#q=" ++ Package},
+ {description, ""},
+ {keywords, []}].

0 comments on commit c091f2e

Please sign in to comment.