Skip to content

Commit

Permalink
Added 'verify' command line command
Browse files Browse the repository at this point in the history
  • Loading branch information
yrashk committed Jan 28, 2011
1 parent 899319d commit 1bb458c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ were the case for `agner spec`.

List the versions of the given `PACKAGE`

agner verify [SPEC FILENAME (agner.config by default)]

Verify specification file for correctness; intended to be used to package maintainers to simplify
their workflow. Currently checks whether 1) specification is a valid file that can be parsed,
2) the URL can be fetched. In the future it will also offer a deeper analysis of specification
correctness.

Packaging
=========

Expand Down
28 changes: 28 additions & 0 deletions src/agner.erl
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,34 @@ main(["fetch"|Args]) ->
end,
stop();

main(["verify"|Args]) ->
OptSpec = [
{spec, undefined, undefined, {string, "agner.config"}, "Specification file (agner.config by default)"}
],
start(),
{ok, {Opts, _}} = getopt:parse(OptSpec, Args),
SpecFile = proplists:get_value(spec, Opts),
case file:consult(SpecFile) of
{error, Reason} ->
io:format("ERROR: Can't read ~s: ~p~n",[SpecFile, Reason]);
{ok, Spec} ->
URL = proplists:get_value(url, Spec),
{A,B,C} = now(),
N = node(),
TmpFile = lists:flatten(io_lib:format("/tmp/agner-~p-~p.~p.~p",[N,A,B,C])),
case (catch agner_download:fetch(URL,TmpFile)) of
ok ->
io:format("~nPASSED~n");
{'EXIT', {Reason, _}} ->
io:format("~nEROR: Can't fetch ~p: ~p~n",[URL, Reason]);
{error, Reason} ->
io:format("~nEROR: Can't fetch ~p: ~p~n",[URL, Reason])
end,
os:cmd("rm -rf " ++ TmpFile)
end,
stop();


main(_) ->
OptSpec = [
{command, undefined, undefined, string, "Command to be executed (e.g. spec)"}
Expand Down

0 comments on commit 1bb458c

Please sign in to comment.