From 37eb061af6f6cf60eea7508e9b079021d95d5c7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Thu, 12 May 2016 13:36:40 +0200 Subject: [PATCH] More user friendly output when no script specified Fixes #256. --- CHANGELOG.md | 4 ++++ lib/byebug/runner.rb | 20 +++++++++++++------- test/runner_test.rb | 4 +++- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7611c049e..477d13033 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/byebug/runner.rb b/lib/byebug/runner.rb index 81af46583..b4015a0e7 100644 --- a/lib/byebug/runner.rb +++ b/lib/byebug/runner.rb @@ -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. # @@ -105,6 +100,8 @@ def run return end + return if no_script? + Byebug.run_init_script if init_script setup_cmd_line_args @@ -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 diff --git a/test/runner_test.rb b/test/runner_test.rb index f9af477db..910b89b19 100644 --- a/test/runner_test.rb +++ b/test/runner_test.rb @@ -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