Method: Optimist.die
- Defined in:
- lib/optimist.rb
.die(arg, msg = nil, error_code = nil) ⇒ Object
Informs the user that their usage of ‘arg’ was wrong, as detailed by ‘msg’, and dies. Example:
do
opt :volume, :default => 0.0
end
die :volume, "too loud" if opts[:volume] > 10.0
die :volume, "too soft" if opts[:volume] < 0.1
In the one-argument case, simply print that message, a notice about -h, and die. Example:
do
opt :whatever # ...
end
Optimist::die "need at least one filename" if ARGV.empty?
An exit code can be provide if needed
Optimist::die "need at least one filename", -2 if ARGV.empty?
1246 1247 1248 1249 1250 1251 1252 |
# File 'lib/optimist.rb', line 1246 def die(arg, msg = nil, error_code = nil) if @last_parser @last_parser.die arg, msg, error_code else raise ArgumentError, "Optimist::die can only be called after Optimist::options" end end |