You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
2.0 KiB

  1. %%% @doc external alias for `rebar_agent' for more convenient
  2. %%% calls from a shell.
  3. -module(r3).
  4. -export([do/1, do/2, async_do/1, async_do/2, break/0, resume/0]).
  5. -export(['$handle_undefined_function'/2]).
  6. -include("rebar.hrl").
  7. %% @doc alias for `rebar_agent:do/1'
  8. -spec do(atom()) -> ok | {error, term()}.
  9. do(Command) -> rebar_agent:do(Command).
  10. %% @doc alias for `rebar_agent:do/2'
  11. -spec do(atom(), atom()) -> ok | {error, term()}.
  12. do(Namespace, Command) -> rebar_agent:do(Namespace, Command).
  13. %% @async_doc alias for `rebar_agent:async_do/1'
  14. -spec async_do(atom()) -> ok | {error, term()}.
  15. async_do(Command) -> rebar_agent:async_do(Command).
  16. %% @async_doc alias for `rebar_agent:async_do/2'
  17. -spec async_do(atom(), atom()) -> ok | {error, term()}.
  18. async_do(Namespace, Command) -> rebar_agent:async_do(Namespace, Command).
  19. break() ->
  20. case whereis(rebar_agent) of % is the shell running
  21. undefined ->
  22. ok;
  23. Pid ->
  24. {dictionary, Dict} = process_info(Pid, dictionary),
  25. case lists:keyfind(cmd_type, 1, Dict) of
  26. {cmd_type, async} ->
  27. Self = self(),
  28. Ref = make_ref(),
  29. spawn_link(fun() ->
  30. register(r3_breakpoint_handler, self()),
  31. receive
  32. resume ->
  33. Self ! Ref
  34. end
  35. end),
  36. io:format(user, "~n=== BREAK ===~n", []),
  37. receive
  38. Ref -> ok
  39. end;
  40. _ ->
  41. ?DEBUG("ignoring breakpoint since command is not run "
  42. "in async mode", []),
  43. ok
  44. end
  45. end.
  46. resume() ->
  47. r3_breakpoint_handler ! resume,
  48. ok.
  49. %% @private defer to rebar_agent
  50. '$handle_undefined_function'(Cmd, Args) ->
  51. rebar_agent:'$handle_undefined_function'(Cmd, Args).