Skip to content

Commit

Permalink
raise specific exception when preconditions fail
Browse files Browse the repository at this point in the history
Improves upon the fix for  #146
  • Loading branch information
davetron5000 committed Jul 3, 2013
1 parent 0198051 commit 69fa3d0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/gli/app_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def run(args) #:nodoc:
call_command(parsing_result)
0
else
exit_now!(nil,65)
raise PreconditionFailed, "preconditions failed"
end
rescue Exception => ex
if the_command.nil? && ex.respond_to?(:command_in_context)
Expand Down
5 changes: 5 additions & 0 deletions lib/gli/exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ class BadCommandLine < StandardError
def exit_code; 64; end
end

class PreconditionFailed < StandardError
include StandardException
def exit_code; 65; end
end

# Indicates the bad command line was an unknown command
class UnknownCommand < BadCommandLine
end
Expand Down
2 changes: 1 addition & 1 deletion test/tc_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ def test_pre_exiting_false_causes_nonzero_exit
@app.pre { |*| false }

assert_equal 65,@app.run(["bs"]) # BSD for "input data incorrect in some way"
assert_equal '',@fake_stderr.to_s
assert_equal 'error: preconditions failed',@fake_stderr.to_s
assert_equal '',@fake_stdout.to_s
end

Expand Down

0 comments on commit 69fa3d0

Please sign in to comment.