Merge remote-tracking branch 'canonical/next'
[sinan.git] / src / sin_task_echo.erl
blob972ce8d652c2c3f20f8223126867554b56952471
1 %% -*- mode: Erlang; fill-column: 80; comment-column: 75; -*-
2 %%%-------------------------------------------------------------------
3 %%%---------------------------------------------------------------------------
4 %%% @author Eric Merritt <ericbmerritt@gmail.com>
5 %%% @doc
6 %%% This provides echo functionality to sinan. The ability to echo paths,
7 %%% include directories, etc to The caller
8 %%% @end
9 %%% @copyright (C) 2012 Erlware
10 %%%---------------------------------------------------------------------------
11 -module(sin_task_echo).
13 -behaviour(sin_task).
15 -include_lib("sinan/include/sinan.hrl").
17 %% API
18 -export([description/0, do_task/2]).
20 -define(TASK, echo).
21 -define(DEPS, [depends]).
23 %%====================================================================
24 %% API
25 %%====================================================================
27 %% @doc provides a description of this task
28 -spec description() -> sin_task:task_description().
29 description() ->
31 Desc = "
32 echo Task
33 =========
35 This task echos the information that the user requests to back to the caller in
36 a way that erlang can make use of. It mostly exists to make it easier to
37 integrate Sinan with make.
39 The two support arguments at the moment are `paths` and `includes`
41 You can get other information out of the state but it will not be nicely
42 formatted",
44 #task{name = ?TASK,
45 task_impl = ?MODULE,
46 bare = false,
47 deps = ?DEPS,
48 example = "echo paths",
49 desc = Desc,
50 short_desc = "Displays the requested information on the command line",
51 opts = []}.
53 %% @doc run all tests for all modules in the system
54 do_task(Config, State0) ->
55 lists:foldl(fun print_correct/2, State0, Config:match(additional_args, [])).
58 %%====================================================================
59 %%% Internal functions
60 %%====================================================================
61 print_correct("paths", State) ->
62 lists:foreach(fun(#app{path=Path}) ->
63 io:format("-pa ~s ", [filename:join(Path, "ebin")])
64 end, sin_state:get_value(release_apps, State)),
65 State;
66 print_correct("includes", State) ->
67 lists:foreach(fun(#app{path=Path}) ->
68 io:format("-I ~s ", [filename:join(Path, "include")])
69 end, sin_state:get_value(release_apps, State)),
70 State;
71 print_correct(Else, State) ->
72 AtomRep = erlang:list_to_atom(Else),
73 io:format("~s ", [sin_state:get_value(AtomRep, State)]),
74 State.