Class: Byebug::RestartCommand

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

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



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

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



46
47
48
# File 'lib/byebug/commands/control.rb', line 46

def names
  %w(restart)
end

Instance Method Details

#executeObject



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

def execute
  prog = Byebug::PROG_SCRIPT if defined?(Byebug::PROG_SCRIPT)
  byebug_script = Byebug::BYEBUG_SCRIPT if defined?(Byebug::BYEBUG_SCRIPT)

  return errmsg "Don't know name of debugged program\n" unless prog

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

  if byebug_script
    cmd = "#{byebug_script} #{prog}"
  else
    print "Byebug was not called from the outset...\n"
    if File.executable?(prog)
      cmd = prog
    else
      print "Ruby program #{prog} not executable... We'll wrap it in a ruby call\n"
      cmd = "ruby -rbyebug -I#{$:.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.
  print "Re exec'ing:\n\t#{cmd}\n"
  exec cmd
rescue Errno::EOPNOTSUPP
  print "Restart command is not available at this time.\n"
end

#regexpObject



5
6
7
# File 'lib/byebug/commands/control.rb', line 5

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