mad.htm 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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="../index.html">MAD</a>
  8. <a href="#" style="background:#ededed;">API</a>
  9. <div class="dropdown">
  10. <a onclick="drop()" class="dropbtn">EN</a>
  11. <div id="dropdown" class="dropdown-content">
  12. <a href="https://n2o.dev/deps/mad/man/ua/mad.htm">UA</a>
  13. <a href="https://mad.n2o.dev/man/mad.htm">EN</a>
  14. </div>
  15. </div>
  16. </nav><header>
  17. <a href="../index.html"><img src="https://openmoji.org/data/color/svg/26A1.svg" /></a>
  18. <h1>MAD</h1>
  19. </header><main>
  20. <section>
  21. <h3>INTRO</h3>
  22. <p>MAD module provides user level interface for console commands.</p>
  23. <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>
  24. </section>
  25. <section>
  26. <h3>PROFILE</h3>
  27. <p>Each MAD profile must imeplent exposed API:</p>
  28. <figure><code>
  29. -define(MAD,[compile/1,app/1,get/1,release/1,resolve/1,clean/1,
  30. start/1,attach/1,stop/1,sh/1,deps/1,up/1,fetch/1,
  31. static/1,eunit/1,strip/1]).
  32. </code></figure>
  33. <figure><code>
  34. -type return() :: [] | {ok,any()} | {error,any()}.
  35. </code></figure>
  36. <p>Each function from exposed API has same signature from list of string
  37. to sum of nil and error protocols.</p>
  38. <h4>compile(list(string())) -> return().</h4>
  39. <h4>app(list(string())) -> return().</h4>
  40. <h4>get(list(string())) -> return().</h4>
  41. <h4>release(list(string())) -> return().</h4>
  42. <h4>clean(list(string())) -> return().</h4>
  43. <h4>start(list(string())) -> return().</h4>
  44. <h4>stop(list(string())) -> return().</h4>
  45. <h4>sh(list(string())) -> return().</h4>
  46. <h4>deps(list(string())) -> return().</h4>
  47. <h4>up(list(string())) -> return().</h4>
  48. <h4>sh(list(string())) -> return().</h4>
  49. <h4>fetch(list(string())) -> return().</h4>
  50. <h4>static(list(string())) -> return().</h4>
  51. <h4>eunit(list(string())) -> return().</h4>
  52. <h4>strip(list(string())) -> return().</h4>
  53. </section>
  54. <section>
  55. <h3>LOOP</h3>
  56. <h4>main(list(string())) -> integer().</h4>
  57. <p>Simple yet understandable command processing and error loop.
  58. Function <b>atomize/1</b> helps to accumulate
  59. known arguments as atoms. Function <b>profile/0</b>
  60. retrieves module with MAD API implementation.
  61. <b>main/1</b> function returns error status to OS with halt.</p>
  62. <figure><code>
  63. main(Params) ->
  64. { _Invalid, Valid } = lists:foldr(
  65. fun (X,{C,R}) when is_atom(X) -> {[],[{X,C}|R]};
  66. (X,{C,R}) -> {[X|C],R}
  67. end, {[],[]}, lists:map(fun atomize/1, Params)),
  68. halt(return(
  69. lists:any(fun({error,X}) -> mad:info("~s~n",[X]), true;
  70. (_) -> false end,
  71. lists:flatten([
  72. lists:foldl(
  73. fun ({Fun,Arg},ErrAcc) ->
  74. mad_hooks:run_hooks(pre, Fun),
  75. Errors = errors((profile()):Fun(Arg)),
  76. mad_hooks:run_hooks(post, Fun),
  77. Errors ++ ErrAcc
  78. end, [], Valid)])))).
  79. </code></figure>
  80. </section>
  81. <section>
  82. <p>This module may refer to:
  83. <a href="mad_local.htm"><b>mad_local</b></a>.
  84. </p>
  85. </section>
  86. </main><footer>
  87. 2005—2018 © Synrc Research Center
  88. </footer>
  89. <script>function drop(){document.getElementById("dropdown").classList.toggle("show");}</script>
  90. </body></html>