Class: Byebug::Runner
- Inherits:
-
Object
- Object
- Byebug::Runner
- Includes:
- Helpers::ParseHelper
- Defined in:
- lib/byebug/runner.rb
Overview
Responsible for starting the debugger when started from the command line.
Instance Attribute Summary collapse
-
#help ⇒ Object
Special working modes that don’t actually start the debugger.
- #init_script ⇒ Object
- #interface ⇒ Object
-
#quit ⇒ Object
Signals that we should exit after the debugged program is finished.
-
#remote ⇒ Object
Special working modes that don’t actually start the debugger.
-
#stop ⇒ Object
Signals that we should stop before program starts.
-
#version ⇒ Object
Special working modes that don’t actually start the debugger.
Instance Method Summary collapse
-
#banner ⇒ Object
Usage banner.
-
#debug_program ⇒ Object
Debugs a script only if syntax checks okay.
-
#error_in_script? ⇒ Boolean
There is an error with the specified script.
-
#initialize(stop = true, quit = true) ⇒ Runner
constructor
starting the program.
-
#invalid_script? ⇒ Boolean
Checks the debugged script has correct syntax.
-
#no_script? ⇒ Boolean
No script to debug specified.
-
#non_existing_script? ⇒ Boolean
Extracts debugged program from command line args.
-
#non_script_option? ⇒ Boolean
An option that doesn’t need a script specified was given.
-
#option_parser ⇒ Object
Processes options passed from the command line.
-
#print_error(msg) ⇒ Object
Prints an error message and a help string.
-
#run ⇒ Object
Starts byebug to debug a program.
-
#which(cmd) ⇒ Object
Cross-platform way of finding an executable in the $PATH.
Methods included from Helpers::ParseHelper
#get_int, #parse_steps, #syntax_valid?
Constructor Details
#initialize(stop = true, quit = true) ⇒ Runner
starting the program.
finishing the program.
43 44 45 46 |
# File 'lib/byebug/runner.rb', line 43 def initialize(stop = true, quit = true) @stop = stop @quit = quit end |
Instance Attribute Details
#help ⇒ Object
Special working modes that don’t actually start the debugger.
19 20 21 |
# File 'lib/byebug/runner.rb', line 19 def help @help end |
#init_script ⇒ Object
66 67 68 |
# File 'lib/byebug/runner.rb', line 66 def init_script defined?(@init_script) ? @init_script : true end |
#interface ⇒ Object
103 104 105 |
# File 'lib/byebug/runner.rb', line 103 def interface @interface ||= LocalInterface.new end |
#quit ⇒ Object
Signals that we should exit after the debugged program is finished.
24 25 26 |
# File 'lib/byebug/runner.rb', line 24 def quit @quit end |
#remote ⇒ Object
Special working modes that don’t actually start the debugger.
19 20 21 |
# File 'lib/byebug/runner.rb', line 19 def remote @remote end |
#stop ⇒ Object
Signals that we should stop before program starts
29 30 31 |
# File 'lib/byebug/runner.rb', line 29 def stop @stop end |
#version ⇒ Object
Special working modes that don’t actually start the debugger.
19 20 21 |
# File 'lib/byebug/runner.rb', line 19 def version @version end |
Instance Method Details
#banner ⇒ Object
Usage banner.
73 74 75 76 77 78 79 80 81 |
# File 'lib/byebug/runner.rb', line 73 def <<-EOB.gsub(/^ {6}/, '') byebug #{Byebug::VERSION} Usage: byebug [options] <script.rb> -- <script.rb parameters> EOB end |
#debug_program ⇒ Object
Debugs a script only if syntax checks okay.
173 174 175 176 |
# 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? ⇒ Boolean
There is an error with the specified script
128 129 130 |
# File 'lib/byebug/runner.rb', line 128 def error_in_script? no_script? || non_existing_script? || invalid_script? end |
#invalid_script? ⇒ Boolean
Checks the debugged script has correct syntax
163 164 165 166 167 168 |
# 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? ⇒ Boolean
No script to debug specified
135 136 137 138 139 140 |
# 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? ⇒ Boolean
Extracts debugged program from command line args.
145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# 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? ⇒ Boolean
An option that doesn’t need a script specified was given
121 122 123 |
# File 'lib/byebug/runner.rb', line 121 def non_script_option? version || help || remote end |
#option_parser ⇒ Object
Processes options passed from the command line.
110 111 112 113 114 115 116 |
# File 'lib/byebug/runner.rb', line 110 def option_parser @option_parser ||= OptionParser.new(, 25) do |opts| opts. = OptionSetter.new(self, opts).setup end end |
#print_error(msg) ⇒ Object
Prints an error message and a help string
199 200 201 202 |
# File 'lib/byebug/runner.rb', line 199 def print_error(msg) interface.errmsg(msg) interface.puts(option_parser.help) end |
#run ⇒ Object
Starts byebug to debug a program.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# 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 |
#which(cmd) ⇒ Object
Cross-platform way of finding an executable in the $PATH. Borrowed from: stackoverflow.com/questions/2108727
182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/byebug/runner.rb', line 182 def which(cmd) return File.(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 |