support required arguments
fawaf opened this issue · comments
if a required argument is not passed in, the program should error.
e.g.
% ruby foo.rb --arg blah
...output...
% ruby foo.rb
required argument --arg not given
%
I had this in the previous version and it was never really used. You can add it yourself really easily though:
#!/usr/bin/env ruby
require "slop"
opts = Slop.parse do |o|
o.string "--name"
end
unless opts.name?
raise "required --name option not provided"
end
ah, bummer. it would be great to have it built in to the gem.
I would second that request, because the support is responsibility of the option parser I think.
Fair comment. Would one of you be up for tackling this? I think something like this would work:
Slop.parse do |o|
o.string "--name", required: true
end
And if --name
is not present, we would raise a Slop::MissingRequiredOption
or something. WDYT?
Hum, let me see if I find the time to implement that then!
It seems to me that what you thought of is the most intuitive solution indeed.