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.
Defined Under Namespace
Classes: InvalidScript, NoScript, NonExistentScript
Instance Attribute Summary collapse
-
#help ⇒ Object
Special working modes that don’t actually start the debugger.
- #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.
-
#initialize(stop = true, quit = true) ⇒ Runner
constructor
starting the program.
-
#prepare_options ⇒ Object
Processes options passed from the command line.
-
#run ⇒ Object
Starts byebug to debug a program.
-
#setup_cmd_line_args ⇒ Object
Extracts debugged program from command line args.
-
#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.
53 54 55 56 |
# File 'lib/byebug/runner.rb', line 53 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.
34 35 36 |
# File 'lib/byebug/runner.rb', line 34 def help @help end |
#interface ⇒ Object
112 113 114 |
# File 'lib/byebug/runner.rb', line 112 def interface @interface ||= LocalInterface.new end |
#quit ⇒ Object
Signals that we should exit after the debugged program is finished.
39 40 41 |
# File 'lib/byebug/runner.rb', line 39 def quit @quit end |
#remote ⇒ Object
Special working modes that don’t actually start the debugger.
34 35 36 |
# File 'lib/byebug/runner.rb', line 34 def remote @remote end |
#stop ⇒ Object
Signals that we should stop before program starts
44 45 46 |
# File 'lib/byebug/runner.rb', line 44 def stop @stop end |
#version ⇒ Object
Special working modes that don’t actually start the debugger.
34 35 36 |
# File 'lib/byebug/runner.rb', line 34 def version @version end |
Instance Method Details
#banner ⇒ Object
Usage banner.
77 78 79 80 81 82 83 84 85 |
# File 'lib/byebug/runner.rb', line 77 def <<-EOB.gsub(/^ {8}/, '') byebug #{Byebug::VERSION} Usage: byebug [options] <script.rb> -- <script.rb parameters> EOB end |
#debug_program ⇒ Object
Debugs a script only if syntax checks okay.
145 146 147 148 149 150 151 |
# 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 |
#prepare_options ⇒ Object
Processes options passed from the command line.
119 120 121 122 123 124 125 |
# File 'lib/byebug/runner.rb', line 119 def OptionParser.new(, 25) do |opts| opts. = OptionSetter.new(self, opts).setup end end |
#run ⇒ Object
Starts byebug to debug a program.
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/byebug/runner.rb', line 90 def run .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 |
#setup_cmd_line_args ⇒ Object
Extracts debugged program from command line args.
130 131 132 133 134 135 136 137 138 139 140 |
# 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 |
#which(cmd) ⇒ Object
Cross-platform way of finding an executable in the $PATH. Borrowed from: stackoverflow.com/questions/2108727
157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/byebug/runner.rb', line 157 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 |