Permalink
Browse files

dialyzed

  • Loading branch information...
1 parent 682dcdc commit f35602018e3317dd12d2cdef591f00887f2457bf Dmytro Lytovchenko committed Feb 8, 2014
Showing with 52 additions and 36 deletions.
  1. +6 −5 include/epm.hrl
  2. +30 −12 src/epm.erl
  3. +13 −13 src/epm_core.erl
  4. +1 −1 src/epm_deps.erl
  5. +2 −5 src/epm_ops.erl
View
@@ -5,21 +5,22 @@
-define(any_author, any_author).
-define(any_vsn, any_vsn).
+-define(any_platform, any_platform).
-define(EXIT(Format, Args), exit(lists:flatten(io_lib:format(Format, Args)))).
--type platform() :: x86 | x64.
+-type platform() :: x86 | x64 | ?any_platform.
-type erlangvsn() :: binary().
-record(repoid, { name :: string()
}).
-type repoid() :: #repoid{}.
%% Unified global identifier for package
--record(pkgid, { author :: string()
+-record(pkgid, { author=?any_author :: string() | ?any_author
, pkg_name :: string()
- , platform :: platform()
- , vsn :: string()
- , erlang_vsn :: erlangvsn()
+ , platform=?any_platform :: platform()
+ , vsn=?any_vsn :: string() | ?any_vsn
+ , erlang_vsn=?any_vsn :: erlangvsn() | ?any_vsn
}).
-type pkgid() :: #pkgid{}.
View
@@ -1,6 +1,12 @@
-module(epm).
-export([main/1
- , author/1, name/1, vsn/1, erlang_vsn/1, as_string/1, equals/2]).
+ , author/1
+ , name/1
+ , vsn/1
+ , erlang_vsn/1
+ , as_string/1
+ , equals/2
+ , platform/1]).
-include("epm.hrl").
@@ -32,25 +38,37 @@ setup_proxy() ->
epm_util:set_net_timeout(epm_cfg:get(net_timeout, 6000)).
%%------------------------------------------------------------------------------
-author(#pkg{id=#pkgid{author=X}}) -> X.
+author(#pkg{id=#pkgid{author=X}}) -> X;
+author(#pkgid{author=X}) -> X.
name(#pkg{id=#pkgid{pkg_name=X}}) -> X;
+name(#pkgid{pkg_name=X}) -> X;
name(#repo{id=#repoid{name=X}}) -> X.
-vsn(#pkg{id=#pkgid{vsn=X}}) -> X.
+vsn(#pkg{id=#pkgid{vsn=X}}) -> X;
+vsn(#pkgid{vsn=X}) -> X.
-platform(#pkg{id=#pkgid{platform=X}}) -> X.
+platform(#pkg{id=#pkgid{platform=X}}) -> X;
+platform(#pkgid{platform=X}) -> X.
-erlang_vsn(#pkg{id=#pkgid{erlang_vsn=X}}) -> X.
+erlang_vsn(#pkg{id=#pkgid{erlang_vsn=X}}) -> X;
+erlang_vsn(#pkgid{erlang_vsn=X}) -> X.
+%%------------------------------------------------------------------------------
+as_string(#pkg{id=Id}) -> as_string(Id);
+as_string(#pkgid{author=?any_author, pkg_name=N, vsn=V, platform=P, erlang_vsn=E}) ->
+ lists:flatten(io_lib:format("Package ~s/~s ~s/~s", [N,V, P,E]));
as_string(#pkgid{author=A, pkg_name=N, vsn=V, platform=P, erlang_vsn=E}) ->
- lists:flatten(io_lib:format("~s/~s/~s ~s/~s", [A,N,V, P,E]));
+ lists:flatten(io_lib:format("Package by ~s ~s/~s ~s/~s", [A,N,V, P,E]));
as_string(#repo{id=I, description=_D, url=U}) ->
- lists:flatten(io_lib:format("Repo ~s url=~s", [I, U])).
+ lists:flatten(io_lib:format("Repo ~s url=~s", [I, U]));
+as_string(#repoid{name=N}) ->
+ lists:flatten(io_lib:format("Repo id ~s", [N]));
+as_string(undefined) -> "undefined".
equals(#pkgid{}=P1, #pkgid{}=P2) ->
- (author(P1) == author(P2) orelse author(P2) =:= ?any_author)
- andalso (name(P1) == name(P2))
- andalso (vsn(P1) == vsn(P2))
- andalso (erlang_vsn(P1) == vsn(P2))
- andalso (platform(P1) == platform(P2)).
+ (author(P1) =:= author(P2) orelse author(P2) =:= ?any_author)
+ andalso (name(P1) =:= name(P2))
+ andalso (vsn(P1) =:= vsn(P2) orelse vsn(P1) =:= ?any_vsn)
+ andalso (erlang_vsn(P1) =:= erlang_vsn(P2) orelse erlang_vsn(P1) =:= ?any_vsn)
+ andalso (platform(P1) =:= platform(P2)).
View
@@ -88,15 +88,15 @@ execute(State=#epm_state{}, ["info" | Args]) ->
io:format("INSTALLED~n"),
io:format("===============================~n"),
- lists:foldl(
- fun(Package, Count) ->
- case Count of
- 0 -> ok;
- _ -> io:format("~n")
+ F = fun(Package=#pkg{}, Count) ->
+ case Count of
+ 0 -> ok;
+ _ -> io:format("~n")
+ end,
+ epm_ops:print_installed_package_info(Package),
+ Count + 1
end,
- epm_ops:print_installed_package_info(Package),
- Count + 1
- end, 0, lists:reverse(Installed))
+ lists:foldl(F, 0, lists:reverse(Installed))
end,
case NotInstalled of
@@ -227,11 +227,11 @@ collect_args_internal(Target, [Arg | Rest], Packages, Flags) ->
, Flags);
{Type, Tag, 0} -> %% tag with no trailing value
case Type of
- project ->
- [#pkg{args = Args} = Package|OtherPackages] = Packages,
- collect_args_internal(Target, Rest
- , [Package#pkg{args = Args ++ [Tag]}|OtherPackages]
- , Flags);
+%% project ->
+%% [#pkg{args = Args} = Package|OtherPackages] = Packages,
+%% collect_args_internal(Target, Rest
+%% , [Package#pkg{args = Args ++ [Tag]}|OtherPackages]
+%% , Flags);
global ->
collect_args_internal(Target, Rest, Packages, [Tag|Flags])
end;
View
@@ -17,7 +17,7 @@
package_dependencies(Packages) ->
_RepoPlugins = epm_cfg:get(repo_plugins, ?DEFAULT_API_MODULES),
G = digraph:new(),
- UpdatedPackages = [],
+ UpdatedPackages = dict:new(),
%% UpdatedPackages = package_dependencies_internal(
%% Packages, RepoPlugins, G, undefined, dict:new()),
Deps = digraph_utils:topsort(G),
View
@@ -208,11 +208,8 @@ print_installed_package_info(Package) ->
case Package#pkg.deps of
[] -> ok;
Deps ->
- io:format(" dependencies: ~n ~s~n", [string:join([
- case U of
- none -> lists:flatten(io_lib:format("~s/~s", [N,V]));
- _ -> lists:flatten(io_lib:format("~s/~s/~s", [U,N,V]))
- end || {U,N,V} <- Deps], "\n ")])
+ io:format(" dependencies: ~n ~s~n",
+ [string:join(lists:map(fun epm:as_string/1, Deps), "\n ")])
end.
print_not_installed_package_info(State=#epm_state{}, Packages) ->

0 comments on commit f356020

Please sign in to comment.