Skip to content

Commit

Permalink
More user friendly output when no script specified
Browse files Browse the repository at this point in the history
Fixes #256.
  • Loading branch information
David Rodríguez committed May 12, 2016
1 parent 51d7416 commit 37eb061
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Master (Unreleased)

### Fixed

* Unfriendly output in byebug's executable when no script specified (#256).

## 9.0.0 - 2016-05-11

### Fixed
Expand Down
20 changes: 13 additions & 7 deletions lib/byebug/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ module Byebug
class Runner
include Helpers::ParseHelper

#
# Error class signaling absence of a script to debug.
#
class NoScript < StandardError; end

#
# Error class signaling a non existent script to debug.
#
Expand Down Expand Up @@ -105,6 +100,8 @@ def run
return
end

return if no_script?

Byebug.run_init_script if init_script

setup_cmd_line_args
Expand Down Expand Up @@ -135,14 +132,23 @@ def option_parser
end
end

#
# No script to debug specified
#
def no_script?
return false unless $ARGV.empty?

interface.errmsg('You must specify a program to debug')
interface.puts(option_parser.help)
true
end

#
# Extracts debugged program from command line args.
#
def setup_cmd_line_args
Byebug.mode = :standalone

raise(NoScript, 'You must specify a program to debug...') if $ARGV.empty?

program = which($ARGV.shift)
program = which($ARGV.shift) if program == which('ruby')
raise(NonExistentScript, "The script doesn't exist") unless program
Expand Down
4 changes: 3 additions & 1 deletion test/runner_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ def test_run_with_remote_option_with_host_and_port_specification

def test_run_without_a_script_to_debug
with_command_line('bin/byebug') do
assert_raises(Runner::NoScript) { runner.run }
runner.run

check_error_includes 'You must specify a program to debug'
end
end

Expand Down

0 comments on commit 37eb061

Please sign in to comment.