| 1 |
# frozen_string_literal: true |
| 2 |
|
| 3 |
module Bundler |
| 4 |
class CLI::Console |
| 5 |
attr_reader :options, :group |
| 6 |
def initialize(options, group) |
| 7 |
@options = options |
| 8 |
@group = group |
| 9 |
end |
| 10 |
|
| 11 |
def run |
| 12 |
message = "bundle console will be replaced by `bin/console` generated by `bundle gem <name>`" |
| 13 |
removed_message = "bundle console has been replaced by `bin/console` generated by `bundle gem <name>`" |
| 14 |
Bundler::SharedHelpers.major_deprecation 2, message, removed_message: removed_message |
| 15 |
|
| 16 |
group ? Bundler.require(:default, *group.split(" ").map!(&:to_sym)) : Bundler.require |
| 17 |
ARGV.clear |
| 18 |
|
| 19 |
console = get_console(Bundler.settings[:console] || "irb") |
| 20 |
console.start |
| 21 |
end |
| 22 |
|
| 23 |
def get_console(name) |
| 24 |
require name |
| 25 |
get_constant(name) |
| 26 |
rescue LoadError |
| 27 |
Bundler.ui.error "Couldn't load console #{name}, falling back to irb" |
| 28 |
require "irb" |
| 29 |
get_constant("irb") |
| 30 |
end |
| 31 |
|
| 32 |
def get_constant(name) |
| 33 |
const_name = { |
| 34 |
"pry" => :Pry, |
| 35 |
"ripl" => :Ripl, |
| 36 |
"irb" => :IRB, |
| 37 |
}[name] |
| 38 |
Object.const_get(const_name) |
| 39 |
rescue NameError |
| 40 |
Bundler.ui.error "Could not find constant #{const_name}" |
| 41 |
exit 1 |
| 42 |
end |
| 43 |
end |
| 44 |
end |