Class: Byebug::RestartCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/byebug/commands/restart.rb

Overview

Restart debugged program from within byebug.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Command

commands, find, format_subcmd, format_subcmds, help, inherited, #initialize, load_commands, #match

Constructor Details

This class inherits a constructor from Byebug::Command

Class Method Details

.descriptionObject



51
52
53
54
55
56
# File 'lib/byebug/commands/restart.rb', line 51

def description
  %(restart|R [args]

    Restart the program. This is a re-exec - all byebug state
    is lost. If command arguments are passed those are used.)
end

.namesObject



47
48
49
# File 'lib/byebug/commands/restart.rb', line 47

def names
  %w(restart)
end

Instance Method Details

#executeObject



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
# File 'lib/byebug/commands/restart.rb', line 12

def execute
  prog = Byebug.debugged_program

  unless File.exist?(File.expand_path(prog))
    return errmsg("Ruby program #{prog} doesn't exist")
  end

  if defined?(BYEBUG_SCRIPT)
    cmd = "#{BYEBUG_SCRIPT} #{prog}"
  else
    puts 'Byebug was not called from the outset...'
    if File.executable?(prog)
      cmd = prog
    else
      puts "Ruby program #{prog} not executable... " \
           "We'll wrap it in a ruby call"
      cmd = "ruby -rbyebug -I#{$LOAD_PATH.join(' -I')} #{prog}"
    end
  end

  if @match[:args]
    cmd += " #{@match[:args]}"
  else
    require 'shellwords'
    cmd += " #{ARGV.compact.shelljoin}"
  end

  # An execv would be preferable to the "exec" below.
  puts "Re exec'ing:\n\t#{cmd}"
  exec cmd
rescue Errno::EOPNOTSUPP
  puts 'Restart command is not available at this time.'
end

#regexpObject



8
9
10
# File 'lib/byebug/commands/restart.rb', line 8

def regexp
  /^\s* (?:restart|R) (?:\s+(?<args>.+))? \s*$/x
end