class Byebug::Runner
Responsible for starting the debugger when started from the command line.
Attributes
Special working modes that don't actually start the debugger.
Signals that we should exit after the debugged program is finished.
Special working modes that don't actually start the debugger.
Signals that we should stop before program starts
Special working modes that don't actually start the debugger.
Public Class Methods
@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 53 def initialize(stop = true, quit = true) @stop = stop @quit = quit end
Public Instance Methods
Debugs a script only if syntax checks okay.
# File lib/byebug/runner.rb, line 145 def debug_program ok = syntax_valid?(File.read($PROGRAM_NAME)) fail(InvalidScript, 'The script has incorrect syntax') unless ok error = Byebug.debug_load($PROGRAM_NAME, stop) puts "#{error}\n#{error.backtrace}" if error end
# File lib/byebug/runner.rb, line 58 def help=(text) @help ||= text interface.puts("\n#{text}\n") end
# File lib/byebug/runner.rb, line 112 def interface @interface ||= LocalInterface.new end
Processes options passed from the command line.
# File lib/byebug/runner.rb, line 119 def prepare_options OptionParser.new(banner, 25) do |opts| opts.banner = banner OptionSetter.new(self, opts).setup end end
# File lib/byebug/runner.rb, line 70 def remote=(host_and_port) @remote ||= Byebug.parse_host_and_port(host_and_port) end
Starts byebug to debug a program.
# File lib/byebug/runner.rb, line 90 def run prepare_options.order!($ARGV) return if version || help if remote Byebug.start_client(*remote) return end setup_cmd_line_args loop do debug_program break if quit ControlProcessor.new.process_commands end end
Extracts debugged program from command line args.
# File lib/byebug/runner.rb, line 130 def setup_cmd_line_args Byebug.mode = :standalone fail(NoScript, 'You must specify a program to debug...') if $ARGV.empty? program = which($ARGV.shift) program = which($ARGV.shift) if program == which('ruby') fail(NonExistentScript, "The script doesn't exist") unless program $PROGRAM_NAME = program end
# File lib/byebug/runner.rb, line 64 def version=(number) @version ||= number interface.puts("\n Running byebug #{number}\n") end
Cross-platform way of finding an executable in the $PATH. Borrowed from: stackoverflow.com/questions/2108727
# File lib/byebug/runner.rb, line 157 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