summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Allard <jonathan@allard.io>2013-09-02 12:09:14 -0400
committerJonathan Allard <jonathan@allard.io>2013-09-02 16:05:57 -0400
commitc53e0a6625f196016e21b17f2af66218e7137a9f (patch)
tree1e0dfb77c078d46b8b47f7c9a6996b6477c1dc90
parenta550d0330e2e57e85e315b9667a78319d68bc5b2 (diff)
downloadbundler-c53e0a6625f196016e21b17f2af66218e7137a9f.tar.gz
Set called console to the one in `bundle config console`
IRB alternatives can be selected by setting the config key `console`, for example with `bundle config console pry`.
-rw-r--r--CHANGELOG.md5
-rw-r--r--lib/bundler/cli.rb37
-rw-r--r--spec/commands/console_spec.rb22
3 files changed, 48 insertions, 16 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 33123378f2..d0e5385b21 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,8 @@
+
+Features:
+
+ - add support for IRB alternatives such as Pry and Ripl (@joallard, @postmodern)
+
## 1.4.0.pre.2
Features:
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb
index 6bb1423767..40cee8dc4c 100644
--- a/lib/bundler/cli.rb
+++ b/lib/bundler/cli.rb
@@ -634,35 +634,40 @@ module Bundler
end
end
- CONSOLES = [
- ['pry', :Pry],
- ['ripl', :Ripl],
- ['irb', :IRB]
- ]
+ CONSOLES = {
+ 'pry' => :Pry,
+ 'ripl' => :Ripl,
+ 'irb' => :IRB,
+ }
desc "console [GROUP]", "Opens an IRB session with the bundle pre-loaded"
def console(group = nil)
group ? Bundler.require(:default, *(group.split.map! {|g| g.to_sym })) : Bundler.require
ARGV.clear
- file, constant = CONSOLES.find do |file,constant|
- begin
- require(file) || true
- rescue LoadError
- false
- end
- end
+ preferred = Bundler.settings[:console] || 'irb'
- unless constant
- Bundler.ui.error "Could not load the Ruby console"
- return
+ # See if console is available
+ begin
+ require preferred || true
+ rescue LoadError
+ false
+
+ # Is it in Gemfile?
+ Bundler.ui.error "Could not load the #{preferred} console"
+ Bundler.ui.info "Falling back on IRB..."
+
+ require 'irb'
+ preferred = 'irb'
end
+ constant = CONSOLES[preferred]
+
console = begin
Object.const_get(constant)
rescue NameError => e
Bundler.ui.error e.inspect
- Bundler.ui.error "Could not load the #{file} console"
+ Bundler.ui.error "Could not load the #{constant} console"
return
end
diff --git a/spec/commands/console_spec.rb b/spec/commands/console_spec.rb
index b72883a01c..75d6796c9d 100644
--- a/spec/commands/console_spec.rb
+++ b/spec/commands/console_spec.rb
@@ -18,6 +18,28 @@ describe "bundle console" do
expect(out).to include("0.9.1")
end
+ it "starts another REPL if configured as such" do
+ bundle "config console pry"
+
+ bundle "console" do |input|
+ input.puts("__callee__")
+ input.puts("exit")
+ end
+ expect(out).to include("pry")
+ end
+
+ it "falls back to IRB if the other REPL isn't available" do
+ bundle "config console pry"
+ # make sure pry isn't there
+
+ bundle "console" do |input|
+ input.puts("__callee__")
+ input.puts("exit")
+ end
+ expect(out).to include("irb")
+ end
+
+
it "doesn't load any other groups" do
bundle "console" do |input|
input.puts("puts ACTIVESUPPORT")