Method: Trollop.die
- Defined in:
- lib/trollop.rb
.die(arg, msg = 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
Trollop::die "need at least one filename" if ARGV.empty?
772 773 774 775 776 777 778 |
# File 'lib/trollop.rb', line 772 def die arg, msg=nil if @last_parser @last_parser.die arg, msg else raise ArgumentError, "Trollop::die can only be called after Trollop::options" end end |