summaryrefslogtreecommitdiff
path: root/lib/bundler/cli/console.rb
blob: bf000936fcb024a61e8ae7cc69f92f60e399f801 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
module Bundler
  class CLI::Console
    attr_reader :options, :group, :consoles
    def initialize(options, group, consoles)
      @options = options
      @group = group
      @consoles = consoles
    end

    def run
      group ? Bundler.require(:default, *(group.split.map! {|g| g.to_sym })) : Bundler.require
      ARGV.clear

      preferred = Bundler.settings[:console] || 'irb'

      # See if console is available
      begin
        require preferred || true
      rescue LoadError
        # 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 #{constant} console"
                  return
                end

      console.start
    end

  end
end