diff --git a/THANKS b/THANKS index 3cccd192..a2de691a 100644 --- a/THANKS +++ b/THANKS @@ -144,3 +144,4 @@ Niklas Johansson Bryan Paxton Justin Wood Guilherme Andrade +Manas Chaudhari diff --git a/src/r3.erl b/src/r3.erl index 60a585dc..5e3b2222 100644 --- a/src/r3.erl +++ b/src/r3.erl @@ -1,26 +1,34 @@ %%% @doc external alias for `rebar_agent' for more convenient %%% calls from a shell. -module(r3). --export([do/1, do/2, async_do/1, async_do/2, break/0, resume/0]). +-export([do/1, do/2, do/3, async_do/1, async_do/2, async_do/3, break/0, resume/0]). -export(['$handle_undefined_function'/2]). -include("rebar.hrl"). %% @doc alias for `rebar_agent:do/1' --spec do(atom()) -> ok | {error, term()}. +-spec do(atom() | string()) -> ok | {error, term()}. do(Command) -> rebar_agent:do(Command). %% @doc alias for `rebar_agent:do/2' --spec do(atom(), atom()) -> ok | {error, term()}. +-spec do(atom(), atom() | string()) -> ok | {error, term()}. do(Namespace, Command) -> rebar_agent:do(Namespace, Command). +%% @doc alias for `rebar_agent:do/3' +-spec do(atom(), atom(), string()) -> ok | {error, term()}. +do(Namespace, Command, Args) -> rebar_agent:do(Namespace, Command, Args). + %% @doc alias for `rebar_agent:async_do/1' --spec async_do(atom()) -> ok | {error, term()}. +-spec async_do(atom()) -> ok. async_do(Command) -> rebar_agent:async_do(Command). %% @doc alias for `rebar_agent:async_do/2' --spec async_do(atom(), atom()) -> ok | {error, term()}. +-spec async_do(atom(), atom()) -> ok. async_do(Namespace, Command) -> rebar_agent:async_do(Namespace, Command). +%% @doc alias for `rebar_agent:async_do/3' +-spec async_do(atom(), atom(), string()) -> ok. +async_do(Namespace, Command, Args) -> rebar_agent:async_do(Namespace, Command, Args). + break() -> case whereis(rebar_agent) of % is the shell running undefined -> diff --git a/src/rebar_agent.erl b/src/rebar_agent.erl index b669ac45..c4eccc9d 100644 --- a/src/rebar_agent.erl +++ b/src/rebar_agent.erl @@ -1,7 +1,7 @@ %%% @doc Runs a process that holds a rebar3 state and can be used %%% to statefully maintain loaded project state into a running VM. -module(rebar_agent). --export([start_link/1, do/1, do/2, async_do/1, async_do/2]). +-export([start_link/1, do/1, do/2, do/3, async_do/1, async_do/2, async_do/3]). -export(['$handle_undefined_function'/2]). -export([init/1, handle_call/3, handle_cast/2, handle_info/2, @@ -21,7 +21,7 @@ start_link(State) -> gen_server:start_link({local, ?MODULE}, ?MODULE, State, []). %% @doc runs a given command in the agent's context. --spec do(atom()) -> ok | {error, term()}. +-spec do(atom() | string()) -> ok | {error, term()}. do(Command) when is_atom(Command) -> gen_server:call(?MODULE, {cmd, Command}, infinity); do(Args) when is_list(Args) -> @@ -29,13 +29,17 @@ do(Args) when is_list(Args) -> %% @doc runs a given command in the agent's context, under a given %% namespace. --spec do(atom(), atom()) -> ok | {error, term()}. +-spec do(atom(), atom() | string()) -> ok | {error, term()}. do(Namespace, Command) when is_atom(Namespace), is_atom(Command) -> gen_server:call(?MODULE, {cmd, Namespace, Command}, infinity); do(Namespace, Args) when is_atom(Namespace), is_list(Args) -> gen_server:call(?MODULE, {cmd, Namespace, do, Args}, infinity). --spec async_do(atom()) -> ok | {error, term()}. +-spec do(atom(), atom(), string()) -> ok | {error, term()}. +do(Namespace, Command, Args) when is_atom(Namespace), is_atom(Command), is_list(Args) -> + gen_server:call(?MODULE, {cmd, Namespace, Command, Args}, infinity). + +-spec async_do(atom()) -> ok. async_do(Command) when is_atom(Command) -> gen_server:cast(?MODULE, {cmd, Command}); async_do(Args) when is_list(Args) -> @@ -47,6 +51,10 @@ async_do(Namespace, Command) when is_atom(Namespace), is_atom(Command) -> async_do(Namespace, Args) when is_atom(Namespace), is_list(Args) -> gen_server:cast(?MODULE, {cmd, Namespace, do, Args}). +-spec async_do(atom(), atom(), string()) -> ok. +async_do(Namespace, Command, Args) when is_atom(Namespace), is_atom(Command), is_list(Args) -> + gen_server:cast(?MODULE, {cmd, Namespace, Command, Args}). + '$handle_undefined_function'(Cmd, [Namespace, Args]) -> gen_server:call(?MODULE, {cmd, Namespace, Cmd, Args}, infinity); '$handle_undefined_function'(Cmd, [Args]) ->