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.

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