Sha256: 461c6100dadf4adccb11af54527129582cf49997470605ede77db2dc413d3587

Contents?: true

Size: 1.24 KB

Versions: 3

Compression:

Stored size: 1.24 KB

Contents

require 'byebug/command'
require 'byebug/helpers/bin'
require 'byebug/helpers/path'
require 'shellwords'
require 'English'
require 'rbconfig'

module Byebug
  #
  # Restart debugged program from within byebug.
  #
  class RestartCommand < Command
    include Helpers::BinHelper
    include Helpers::PathHelper

    self.allow_in_control = true
    self.allow_in_post_mortem = true

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

    def self.description
      <<-EOD
        restart [args]

        #{short_description}

        This is a re-exec - all byebug state is lost. If command arguments are
        passed those are used.
      EOD
    end

    def self.short_description
      'Restarts the debugged program'
    end

    def execute
      cmd = [$PROGRAM_NAME]

      cmd = prepend_byebug_bin(cmd)
      cmd = prepend_ruby_bin(cmd)

      cmd += (@match[:args] ? @match[:args].shellsplit : $ARGV)

      puts pr('restart.success', cmd: cmd.shelljoin)
      Kernel.exec(*cmd)
    end

    private

    def prepend_byebug_bin(cmd)
      cmd.unshift(bin_file) if Byebug.mode == :standalone
      cmd
    end

    def prepend_ruby_bin(cmd)
      cmd.unshift(RbConfig.ruby) if which('ruby') != which(cmd.first)
      cmd
    end
  end
end

Version data entries

3 entries across 3 versions & 3 rubygems

Version Path
dirwatch-0.0.2 vendor/bundle/ruby/2.3.0/gems/byebug-9.1.0/lib/byebug/commands/restart.rb
tdiary-5.0.6 vendor/bundle/gems/byebug-9.1.0/lib/byebug/commands/restart.rb
byebug-9.1.0 lib/byebug/commands/restart.rb