mad.htm 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <html><head><meta charset="utf-8" /><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="description" content="" />
  2. <meta name="author" content="Maxim Sokhatsky" /><title>MAD</title>
  3. <link rel="stylesheet" href="https://n2o.dev/blank.css" />
  4. <link rel="stylesheet" href="https://n2o.dev/zima.css" />
  5. </head><body><nav>
  6. <a href="https://n2o.dev">DEV</a>
  7. <a href="https://mad.n2o.space">MAD</a>
  8. <a href="#" style="background:#ededed;">MAD</a>
  9. </nav><header>
  10. <a href="../index.html"><img src="https://n2o.space/img/Synrc Neo.svg" /></a>
  11. <h1>MAD</h1>
  12. </header><main>
  13. <section>
  14. <h3>INTRO</h3>
  15. <p>MAD module provides user level interface for console commands.</p>
  16. <p></p><blockquote><p></p><ul><li><b><a href="#main">main/1</a></b> — IO parameters.</li><li><b><a href="#help">help/0</a></b> — Display help.</li><li><b><a href="#profile">profile/0</a></b> — Current MAD profile.</li><li><b><a href="#atomize">atomize/1</a></b> — Commands mappings.</li></ul></blockquote>
  17. </section>
  18. <section>
  19. <h3>PROFILE</h3>
  20. <p>Each MAD profile must imeplent exposed API:</p>
  21. <figure><code>
  22. -define(MAD,[compile/1,app/1,get/1,release/1,resolve/1,clean/1,
  23. start/1,attach/1,stop/1,sh/1,deps/1,up/1,fetch/1,
  24. static/1,eunit/1,strip/1]).
  25. </code></figure>
  26. <figure><code>
  27. -type return() :: [] | {ok,any()} | {error,any()}.
  28. </code></figure>
  29. <p>Each function from exposed API has same signature from list of string
  30. to sum of nil and error protocols.</p>
  31. <h4>compile(list(string())) -> return().</h4>
  32. <h4>app(list(string())) -> return().</h4>
  33. <h4>get(list(string())) -> return().</h4>
  34. <h4>release(list(string())) -> return().</h4>
  35. <h4>clean(list(string())) -> return().</h4>
  36. <h4>start(list(string())) -> return().</h4>
  37. <h4>stop(list(string())) -> return().</h4>
  38. <h4>sh(list(string())) -> return().</h4>
  39. <h4>deps(list(string())) -> return().</h4>
  40. <h4>up(list(string())) -> return().</h4>
  41. <h4>sh(list(string())) -> return().</h4>
  42. <h4>fetch(list(string())) -> return().</h4>
  43. <h4>static(list(string())) -> return().</h4>
  44. <h4>eunit(list(string())) -> return().</h4>
  45. <h4>strip(list(string())) -> return().</h4>
  46. </section>
  47. <section>
  48. <h3>LOOP</h3>
  49. <h4>main(list(string())) -> integer().</h4>
  50. <p>Simple yet understandable command processing and error loop.
  51. Function <b>atomize/1</b> helps to accumulate
  52. known agruments as atoms. Function <b>profile/0</b>
  53. retrives module with MAD API implementation.
  54. <b>main/1</b> function returns error status to OS with halt.</p>
  55. <figure><code>
  56. main(Params) ->
  57. { _Invalid, Valid } = lists:foldr(
  58. fun (X,{C,R}) when is_atom(X) -> {[],[{X,C}|R]};
  59. (X,{C,R}) -> {[X|C],R}
  60. end, {[],[]}, lists:map(fun atomize/1, Params)),
  61. halt(return(
  62. lists:any(fun({error,X}) -> mad:info("~s~n",[X]), true;
  63. (_) -> false end,
  64. lists:flatten([
  65. lists:foldl(
  66. fun ({Fun,Arg},ErrAcc) ->
  67. mad_hooks:run_hooks(pre, Fun),
  68. Errors = errors((profile()):Fun(Arg)),
  69. mad_hooks:run_hooks(post, Fun),
  70. Errors ++ ErrAcc
  71. end, [], Valid)])))).
  72. </code></figure>
  73. </section>
  74. <section>
  75. <p>This module may refer to:
  76. <a href="mad_local.htm"><b>mad_local</b></a>.
  77. </p>
  78. </section>
  79. </main><footer>
  80. 2005—2018 © Synrc Research Center
  81. </footer></body></html>