MAD module provides user level interface for console commands.


Each MAD profile must imeplent exposed API:

-define(MAD,[compile/1,app/1,get/1,release/1,resolve/1,clean/1, start/1,attach/1,stop/1,sh/1,deps/1,up/1,fetch/1, static/1,eunit/1,strip/1]).
-type return() :: [] | {ok,any()} | {error,any()}.

Each function from exposed API has same signature from list of string to sum of nil and error protocols.

compile(list(string())) -> return().

app(list(string())) -> return().

get(list(string())) -> return().

release(list(string())) -> return().

clean(list(string())) -> return().

start(list(string())) -> return().

stop(list(string())) -> return().

sh(list(string())) -> return().

deps(list(string())) -> return().

up(list(string())) -> return().

sh(list(string())) -> return().

fetch(list(string())) -> return().

static(list(string())) -> return().

eunit(list(string())) -> return().

strip(list(string())) -> return().


main(list(string())) -> integer().

Simple yet understandable command processing and error loop. Function atomize/1 helps to accumulate known agruments as atoms. Function profile/0 retrives module with MAD API implementation. main/1 function returns error status to OS with halt.

main(Params) -> { _Invalid, Valid } = lists:foldr( fun (X,{C,R}) when is_atom(X) -> {[],[{X,C}|R]}; (X,{C,R}) -> {[X|C],R} end, {[],[]}, lists:map(fun atomize/1, Params)), halt(return( lists:any(fun({error,X}) -> mad:info("~s~n",[X]), true; (_) -> false end, lists:flatten([ lists:foldl( fun ({Fun,Arg},ErrAcc) -> mad_hooks:run_hooks(pre, Fun), Errors = errors((profile()):Fun(Arg)), mad_hooks:run_hooks(post, Fun), Errors ++ ErrAcc end, [], Valid)])))).

This module may refer to: mad_local.