Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.ruby > #3023
| From | Lee Jarvis <lee@jarvis.co> |
|---|---|
| Newsgroups | comp.lang.ruby |
| Subject | [ANN] Slop 1.5.0 |
| Date | 2011-04-16 13:52 -0500 |
| Organization | Service de news de lacave.net |
| Message-ID | <c8e5a17365f17223334c95510232efb1@ruby-forum.com> (permalink) |
Slop
====
Slop is a simple option parser with an easy to remember syntax and
friendly API.
Github: http://github.com/injekt/slop
Documentation: http://rubydoc.info/github/injekt/slop/master
Slop 1.5 introduces commands. Commands allow you to create nested Slop
objects. See an example here: https://gist.github.com/923386
Installation
------------
### Rubygems
gem install slop
### GitHub
git clone git://github.com/injekt/slop.git
gem build slop.gemspec
gem install slop-<version>.gem
Usage
-----
# parse assumes ARGV, otherwise you can pass it your own Array
opts = Slop.parse do
on :v, :verbose, 'Enable verbose mode' # boolean value
on :n, :name, 'Your name', true # compulsory argument
on :s, :sex, 'Your sex', :optional => false # the same thing
on :a, :age, 'Your age', :optional => true # optional argument
end
# if ARGV is `-v --name 'lee jarvis' -s male`
opts.verbose? #=> true
opts.name? #=> true
opts[:name] #=> 'lee jarvis'
opts.age? #=> false
opts[:age] #=> nil
--
Posted via http://www.ruby-forum.com/.
Back to comp.lang.ruby | Previous | Next | Find similar | Unroll thread
[ANN] Slop 1.5.0 Lee Jarvis <lee@jarvis.co> - 2011-04-16 13:52 -0500
csiph-web