From: "Martin J. Dürst" Date: 2012-11-21T09:52:23+09:00 Subject: [ruby-core:49782] Re: [ruby-trunk - Feature #5010] Add Slop(-like) in stdlib and deprecate current OptionParser API I agree with Rodrigo. If I have to use an option parser, I don't want to waste time shopping around. Also, if no option parser outside optparse gets significant traction outside the Ruby standard library, this means that none of them is significantly better than the current one for a significant percentage of Ruby users. I think the best thing is for the people who really care to get together and merge their work, and then come here with a replacement proposal. Regards, Martin. On 2012/11/21 0:16, trans (Thomas Sawyer) wrote: > > Issue #5010 has been updated by trans (Thomas Sawyer). > > > =begin > @rosenfeld It's not? Maybe a little. But one can always parse ARGV by hand for simple shell scripts. It's not that hard. In fact, a simple helper makes it pretty easy. > > def ARGV.option(opt) > if i = ARGV.index(opt) > ARGV.index(i+1) > end > end > > So I don't think an option parser library is needed in standard libraries. If there ((*has*)) to be something more, then only a very simple library like CLAP (https://github.com/soveran/clap/blob/master/lib/clap.rb) extending ARGV itself, makes the most sense to me. > =end > > ---------------------------------------- > Feature #5010: Add Slop(-like) in stdlib and deprecate current OptionParser API > https://bugs.ruby-lang.org/issues/5010#change-33347 > > Author: rosenfeld (Rodrigo Rosenfeld Rosas) > Status: Assigned > Priority: Low > Assignee: matz (Yukihiro Matsumoto) > Category: > Target version: next minor > > > I always found the OptionParser API not as well designed as it could be. > > I've just found this gem: > > http://lee.jarvis.co/slop/ > > Much better API and I think we should integrate it to Ruby 2.0. > > Take a look at the minimal example shown in OptionParser : > >
>    require 'optparse'
>
>    options = {}
>    OptionParser.new do |opts|
>      opts.banner = "Usage: example.rb [options]"
>
>      opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
>        options[:verbose] = v
>      end
>    end.parse!
>
>    p options
>    p ARGV
> 
> > This is the equivalent in Slop: > >
> require 'slop'
>
> opts = Slop.parse do
>    banner "Usage: example.rb [options]"
>    on :v, :verbose, "Run verbosely", :default =>  true
> end
>
> p opts.to_hash
> 
> >