mad.htm 3.5 KB

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