class Byebug::Runner
Responsible for starting the debugger when started from the command line.
def banner
Usage banner.
def banner prettify <<-BANNER byebug #{Byebug::VERSION} Usage: byebug [options] <script.rb> -- <script.rb parameters> BANNER end
def debug_program
Debugs a script only if syntax checks okay.
def debug_program error = Byebug.debug_load(program, stop) puts "#{error}\n#{error.backtrace}" if error end
def error_in_script?
There is an error with the specified script
def error_in_script? no_script? || non_existing_script? || invalid_script? end
def help=(text)
def help=(text) @help ||= text interface.puts("#{text}\n") end
def init_script
def init_script defined?(@init_script) ? @init_script : true end
def initialize(stop = true, quit = true)
-
quit
(Boolean
) -- Whether the runner should quit right after -
stop
(Boolean
) -- Whether the runner should stop right before
def initialize(stop = true, quit = true) @stop = stop @quit = quit end
def interface
def interface @interface ||= Context.interface end
def invalid_script?
Checks the debugged script has correct syntax
def invalid_script? return false if syntax_valid?(File.read(program)) print_error("The script has incorrect syntax") true end
def no_script?
No script to debug specified
def no_script? return false unless $ARGV.empty? print_error("You must specify a program to debug") true end
def non_existing_script?
Extracts debugged program from command line args.
def non_existing_script? return false if program print_error("The script doesn't exist") true end
def non_script_option?
An option that doesn't need a script specified was given
def non_script_option? version || help || remote end
def option_parser
Processes options passed from the command line.
def option_parser @option_parser ||= OptionParser.new(banner, 25) do |opts| opts.banner = banner OptionSetter.new(self, opts).setup end end
def print_error(msg)
Prints an error message and a help string
def print_error(msg) interface.errmsg(msg) interface.puts(option_parser.help) end
def program
def program @program ||= begin candidate = which($ARGV.shift) if [which("ruby"), RbConfig.ruby].include?(candidate) which($ARGV.shift) else candidate end end end
def remote=(host_and_port)
def remote=(host_and_port) @remote ||= Byebug.parse_host_and_port(host_and_port) Byebug.start_client(*@remote) end
def run
Starts byebug to debug a program.
def run Byebug.mode = :standalone option_parser.order!($ARGV) return if non_script_option? || error_in_script? $PROGRAM_NAME = program Byebug.run_init_script if init_script loop do debug_program break if quit ControlProcessor.new(nil, interface).process_commands end end
def version=(number)
def version=(number) @version ||= number interface.puts prettify <<-VERSION Running byebug #{number} VERSION end