class Byebug::Runner - byebug-9.0.6 Documentation

# class Byebug::Runner

Responsible for starting the debugger when started from the command line.

### Attributes

help[R]

Special working modes that don't actually start the debugger.

init_script[W]

Signals that we should run rc scripts before program starts

interface[W]
quit[RW]

Signals that we should exit after the debugged program is finished.

remote[R]

Special working modes that don't actually start the debugger.

stop[RW]

Signals that we should stop before program starts

version[R]

Special working modes that don't actually start the debugger.

### Public Class Methods

new(stop = true, quit = true) click to toggle source

@param stop [Boolean] Whether the runner should stop right before starting the program.

@param quit [Boolean] Whether the runner should quit right after finishing the program.

    # File lib/byebug/runner.rb, line 43
    def initialize(stop = true, quit = true)
      @stop = stop
      @quit = quit
    end

### Public Instance Methods

banner() click to toggle source

Usage banner.

    # File lib/byebug/runner.rb, line 73
        def banner
          "
            byebug #{Byebug::VERSION}

            Usage: byebug [options] <script.rb> -- <script.rb parameters>

    ".gsub(/^ {6}/, '')
        end

debug_program() click to toggle source

Debugs a script only if syntax checks okay.

    # File lib/byebug/runner.rb, line 173
    def debug_program
      error = Byebug.debug_load($PROGRAM_NAME, stop)
      puts "#{error}\n#{error.backtrace}" if error
    end

error_in_script?() click to toggle source

There is an error with the specified script

    # File lib/byebug/runner.rb, line 128
    def error_in_script?
      no_script? || non_existing_script? || invalid_script?
    end

help=(text) click to toggle source

    # File lib/byebug/runner.rb, line 48
    def help=(text)
      @help ||= text

      interface.puts("#{text}\n")
    end

init_script() click to toggle source

    # File lib/byebug/runner.rb, line 66
    def init_script
      defined?(@init_script) ? @init_script : true
    end

interface() click to toggle source

    # File lib/byebug/runner.rb, line 103
    def interface
      @interface ||= LocalInterface.new
    end

invalid_script?() click to toggle source

Checks the debugged script has correct syntax

    # File lib/byebug/runner.rb, line 163
    def invalid_script?
      return false if syntax_valid?(File.read($PROGRAM_NAME))

      print_error('The script has incorrect syntax')
      true
    end

no_script?() click to toggle source

No script to debug specified

    # File lib/byebug/runner.rb, line 135
    def no_script?
      return false unless $ARGV.empty?

      print_error('You must specify a program to debug')
      true
    end

non_existing_script?() click to toggle source

Extracts debugged program from command line args.

    # File lib/byebug/runner.rb, line 145
    def non_existing_script?
      Byebug.mode = :standalone

      program = which($ARGV.shift)
      program = which($ARGV.shift) if program == which('ruby')

      if program
        $PROGRAM_NAME = program
        false
      else
        print_error("The script doesn't exist")
        true
      end
    end

non_script_option?() click to toggle source

An option that doesn't need a script specified was given

    # File lib/byebug/runner.rb, line 121
    def non_script_option?
      version || help || remote
    end

option_parser() click to toggle source

Processes options passed from the command line.

    # File lib/byebug/runner.rb, line 110
    def option_parser
      @option_parser ||= OptionParser.new(banner, 25) do |opts|
        opts.banner = banner

        OptionSetter.new(self, opts).setup
      end
    end

print_error(msg) click to toggle source

Prints an error message and a help string

    # File lib/byebug/runner.rb, line 199
    def print_error(msg)
      interface.errmsg(msg)
      interface.puts(option_parser.help)
    end

remote=(host_and_port) click to toggle source

    # File lib/byebug/runner.rb, line 60
    def remote=(host_and_port)
      @remote ||= Byebug.parse_host_and_port(host_and_port)

      Byebug.start_client(*@remote)
    end

run() click to toggle source

Starts byebug to debug a program.

    # File lib/byebug/runner.rb, line 86
    def run
      option_parser.order!($ARGV)
      return if non_script_option? || error_in_script?

      Byebug.run_init_script if init_script

      loop do
        debug_program

        break if quit

        ControlProcessor.new.process_commands
      end
    end

version=(number) click to toggle source

    # File lib/byebug/runner.rb, line 54
    def version=(number)
      @version ||= number

      interface.puts("\n  Running byebug #{number}\n")
    end

which(cmd) click to toggle source

Cross-platform way of finding an executable in the $PATH. Borrowed from: stackoverflow.com/questions/2108727

    # File lib/byebug/runner.rb, line 182
    def which(cmd)
      return File.expand_path(cmd) if File.exist?(cmd)

      exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
      ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
        exts.each do |ext|
          exe = File.join(path, "#{cmd}#{ext}")
          return exe if File.executable?(exe) && !File.directory?(exe)
        end
      end

      nil
    end