Class: Byebug::Runner
- Inherits:
-
Object
- Object
- Byebug::Runner
- 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.
- #program ⇒ Object
-
#run ⇒ Object
Starts byebug to debug a program.
Methods included from Helpers::StringHelper
#camelize, #deindent, #prettify
Methods included from Helpers::ParseHelper
#get_int, #parse_steps, #syntax_valid?
Methods included from Helpers::BinHelper
Constructor Details
#initialize(stop = true, quit = true) ⇒ Runner
starting the program.
finishing the program.
47 48 49 50 |
# File 'lib/byebug/runner.rb', line 47 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.
23 24 25 |
# File 'lib/byebug/runner.rb', line 23 def help @help end |
#init_script ⇒ Object
70 71 72 |
# File 'lib/byebug/runner.rb', line 70 def init_script defined?(@init_script) ? @init_script : true end |
#interface ⇒ Object
109 110 111 |
# File 'lib/byebug/runner.rb', line 109 def interface @interface ||= LocalInterface.new end |
#quit ⇒ Object
Signals that we should exit after the debugged program is finished.
28 29 30 |
# File 'lib/byebug/runner.rb', line 28 def quit @quit end |
#remote ⇒ Object
Special working modes that don’t actually start the debugger.
23 24 25 |
# File 'lib/byebug/runner.rb', line 23 def remote @remote end |
#stop ⇒ Object
Signals that we should stop before program starts
33 34 35 |
# File 'lib/byebug/runner.rb', line 33 def stop @stop end |
#version ⇒ Object
Special working modes that don’t actually start the debugger.
23 24 25 |
# File 'lib/byebug/runner.rb', line 23 def version @version end |
Instance Method Details
#banner ⇒ Object
Usage banner.
77 78 79 80 81 82 83 |
# File 'lib/byebug/runner.rb', line 77 def prettify <<-EOB byebug #{Byebug::VERSION} Usage: byebug [options] <script.rb> -- <script.rb parameters> EOB end |
#debug_program ⇒ Object
Debugs a script only if syntax checks okay.
178 179 180 181 |
# File 'lib/byebug/runner.rb', line 178 def debug_program error = Byebug.debug_load(program, stop) puts "#{error}\n#{error.backtrace}" if error end |
#error_in_script? ⇒ Boolean
There is an error with the specified script
141 142 143 |
# File 'lib/byebug/runner.rb', line 141 def error_in_script? no_script? || non_existing_script? || invalid_script? end |
#invalid_script? ⇒ Boolean
Checks the debugged script has correct syntax
168 169 170 171 172 173 |
# File 'lib/byebug/runner.rb', line 168 def invalid_script? return false if syntax_valid?(File.read(program)) print_error('The script has incorrect syntax') true end |
#no_script? ⇒ Boolean
No script to debug specified
148 149 150 151 152 153 |
# File 'lib/byebug/runner.rb', line 148 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.
158 159 160 161 162 163 |
# File 'lib/byebug/runner.rb', line 158 def non_existing_script? return false if program print_error("The script doesn't exist") true end |
#non_script_option? ⇒ Boolean
An option that doesn’t need a script specified was given
134 135 136 |
# File 'lib/byebug/runner.rb', line 134 def non_script_option? version || help || remote end |
#option_parser ⇒ Object
Processes options passed from the command line.
116 117 118 119 120 121 122 |
# File 'lib/byebug/runner.rb', line 116 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
186 187 188 189 |
# File 'lib/byebug/runner.rb', line 186 def print_error(msg) interface.errmsg(msg) interface.puts(option_parser.help) end |
#program ⇒ Object
124 125 126 127 128 129 |
# File 'lib/byebug/runner.rb', line 124 def program @program ||= begin candidate = which($ARGV.shift) candidate == which('ruby') ? which($ARGV.shift) : candidate end end |
#run ⇒ Object
Starts byebug to debug a program.
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/byebug/runner.rb', line 88 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.process_commands end end |