Class: Spider::CommandLine::ConsoleCommand

Inherits:
CmdParse::Command
  • Object
show all
Defined in:
lib/spiderfw/cmd/commands/console.rb

Instance Method Summary collapse

Constructor Details

#initializeConsoleCommand

Returns a new instance of ConsoleCommand.



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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/spiderfw/cmd/commands/console.rb', line 6

def initialize
    super( 'console', false )
    @short_desc = _("Open a console")
    #        @description = _("")
    @opts = {}
    
    self.options = CmdParse::OptionParserWrapper.new do |opt|
        opt.on("--irb [IRB]",  _("Use irb (you can specify the executable to use)"), "-i"){ |irb|
            @opts[:irb] = irb ? irb : 'irb'
        }
        opt.on('--ripl' ,_("User ripl"), "-r"){ |ripl| @opts[:ripl] = true }
        opt.on('--pry', _("Use Pry if available (the default)"))
    end
    
    set_execution_block do
        if @opts[:ripl]
            begin
                require 'rubygems'
                require 'ripl'
            rescue LoadError
                @opts[:irb] = 'irb'
            end
        end
        unless @opts[:irb]
            begin
                require 'rubygems'
                require 'pry'
            rescue LoadError
                @opts[:irb] = 'irb'
            end
        end
        if @opts[:irb]
            ENV['SPIDER_RUNMODE'] = $SPIDER_RUNMODE if ($SPIDER_RUNMODE)
            ENV['SPIDER_CONFIG_SETS'] = $SPIDER_CONFIG_SETS.join(',') if ($SPIDER_CONFIG_SETS)
            exec("#{@opts[:irb]} -I #{$SPIDER_LIB} -r spiderfw/init")
        elsif @opts[:ripl]
            require 'ripl/irb'
            require 'ripl/multi_line' 
            
            Ripl.config[:irb_verbose] = false
            Ripl::Runner.load_rc(Ripl.config[:riplrc])
            
            require 'spiderfw/init'
            Object.send(:remove_const, :IRB) if Object.const_defined?(:IRB)
            Ripl.shell.loop
        else
            try_require 'pry-nav'
            try_require 'pry-stack_explorer'
            require 'spiderfw/init'
            Pry.start
        end
    end


end

Instance Method Details

#try_require(lib) ⇒ Object



62
63
64
65
66
67
# File 'lib/spiderfw/cmd/commands/console.rb', line 62

def try_require(lib)
    begin
       require lib 
    rescue LoadError => e
    end
end