Sha256: 3fabbeb79e1a6995af2f9e61634a2a5c047a588deebaf7f1a71d9050d52a770f

Contents?: true

Size: 1.3 KB

Versions: 6488

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

require_relative "../command"
require_relative "../helpers/bin"
require_relative "../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
      <<-DESCRIPTION
        restart [args]

        #{short_description}

        This is a re-exec - all byebug state is lost. If command arguments are
        passed those are used.
      DESCRIPTION
    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

6,488 entries across 6,485 versions & 29 rubygems

Version Path
cybrid_api_organization_ruby-0.122.67 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/commands/restart.rb
cybrid_api_id_ruby-0.122.67 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/commands/restart.rb
cybrid_api_bank_ruby-0.122.66 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/commands/restart.rb
cybrid_api_organization_ruby-0.122.66 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/commands/restart.rb
cybrid_api_id_ruby-0.122.66 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/commands/restart.rb
cybrid_api_id_ruby-0.122.65 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/commands/restart.rb
cybrid_api_bank_ruby-0.122.65 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/commands/restart.rb
cybrid_api_organization_ruby-0.122.65 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/commands/restart.rb
cybrid_api_bank_ruby-0.122.64 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/commands/restart.rb
cybrid_api_id_ruby-0.122.64 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/commands/restart.rb
cybrid_api_organization_ruby-0.122.64 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/commands/restart.rb
cybrid_api_id_ruby-0.122.60 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/commands/restart.rb
cybrid_api_bank_ruby-0.122.60 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/commands/restart.rb
cybrid_api_organization_ruby-0.122.60 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/commands/restart.rb
cybrid_api_organization_ruby-0.122.59 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/commands/restart.rb
cybrid_api_bank_ruby-0.122.59 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/commands/restart.rb
cybrid_api_id_ruby-0.122.59 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/commands/restart.rb
cybrid_api_bank_ruby-0.122.58 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/commands/restart.rb
cybrid_api_organization_ruby-0.122.58 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/commands/restart.rb
cybrid_api_id_ruby-0.122.58 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/commands/restart.rb