summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFred Hebert <mononcqc@ferd.ca>2014-05-27 08:10:23 -0400
committerFred Hebert <mononcqc@ferd.ca>2014-05-27 08:10:23 -0400
commit763f5dc9ef9f418bdc146c17dac7ac4d611f0768 (patch)
tree607bf37a9e32ef107b2eb8feafd8818c25958693
parent755c6023d181b4aa87a581ac71e96d2de90a015f (diff)
parent89cd24937e1b0dd183082b1bbc05d0a67f33ad98 (diff)
Merge pull request #280 from talentdeficit/bettershell
improve output when using `rebar shell`
-rw-r--r--THANKS1
-rw-r--r--src/rebar.erl3
-rw-r--r--src/rebar_shell.erl55
3 files changed, 38 insertions, 21 deletions
diff --git a/THANKS b/THANKS
index 66d7b25..4ad72c2 100644
--- a/THANKS
+++ b/THANKS
@@ -123,3 +123,4 @@ Dave Thomas
Evgeniy Khramtsov
YeJun Su
Yuki Ito
+alisdair sullivan
diff --git a/src/rebar.erl b/src/rebar.erl
index d5d6c77..a43da5f 100644
--- a/src/rebar.erl
+++ b/src/rebar.erl
@@ -409,6 +409,9 @@ qc Test QuickCheck properties
xref Run cross reference analysis
+shell Start a shell similar to
+ 'erl -pa ebin -pa deps/*/ebin'
+
help Show the program options
version Show version information
">>,
diff --git a/src/rebar_shell.erl b/src/rebar_shell.erl
index 2dbf4a0..348e540 100644
--- a/src/rebar_shell.erl
+++ b/src/rebar_shell.erl
@@ -30,27 +30,40 @@
-include("rebar.hrl").
--export([shell/2]).
+-export([shell/2, info/2]).
+
+%% NOTE:
+%% this is an attempt to replicate `erl -pa ./ebin -pa deps/*/ebin`. it is
+%% mostly successful but does stop and then restart the user io system to get
+%% around issues with rebar being an escript and starting in `noshell` mode.
+%% it also lacks the ctrl-c interrupt handler that `erl` features. ctrl-c will
+%% immediately kill the script. ctrl-g, however, works fine
shell(_Config, _AppFile) ->
- ?CONSOLE("NOTICE: Using experimental 'shell' command~n", []),
- %% backwards way to say we only want this executed
- %% for the "top level" directory
- case is_deps_dir(rebar_utils:get_cwd()) of
- false ->
- true = code:add_pathz(rebar_utils:ebin_dir()),
- user_drv:start(),
- %% this call never returns (until user quits shell)
- shell:server(false, false);
- true ->
- ok
- end,
- ok.
+ true = code:add_pathz(rebar_utils:ebin_dir()),
+ %% terminate the current user
+ ok = supervisor:terminate_child(kernel_sup, user),
+ %% start a new shell (this also starts a new user under the correct group)
+ user_drv:start(),
+ %% enable error_logger's tty output
+ ok = error_logger:swap_handler(tty),
+ %% disable the simple error_logger (which may have been added multiple
+ %% times). removes at most the error_logger added by init and the
+ %% error_logger added by the tty handler
+ ok = remove_error_handler(3),
+ %% this call never returns (until user quits shell)
+ timer:sleep(infinity).
+
+info(help, shell) ->
+ ?CONSOLE(
+ "Start a shell with project and deps preloaded similar to~n"
+ "'erl -pa ebin -pa deps/*/ebin'.~n",
+ []).
-is_deps_dir(Dir) ->
- case lists:reverse(filename:split(Dir)) of
- [_, "deps" | _] ->
- true;
- _V ->
- false
- end.
+remove_error_handler(0) ->
+ ?WARN("Unable to remove simple error_logger handler~n", []);
+remove_error_handler(N) ->
+ case gen_event:delete_handler(error_logger, error_logger, []) of
+ {error, module_not_found} -> ok;
+ {error_logger, _} -> remove_error_handler(N-1)
+ end. \ No newline at end of file