diff options
author | Lee Jarvis <ljjarvis@gmail.com> | 2013-01-06 12:57:33 +0000 |
---|---|---|
committer | Lee Jarvis <ljjarvis@gmail.com> | 2013-01-06 12:57:33 +0000 |
commit | 4dee434894ea5f63d1dcb28f235709b19b6380db (patch) | |
tree | ab66fa271c701e3c18f1678fab96ebee4fb05f03 /README.md | |
parent | 2e7165230be95906963b600216e0712edbc8e423 (diff) | |
download | slop-4dee434894ea5f63d1dcb28f235709b19b6380db.tar.gz |
added list/range/autocreate docs to readme
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 56 |
1 files changed, 51 insertions, 5 deletions
@@ -82,13 +82,59 @@ All of these options can be sent to `Slop.new` or `Slop.parse` in Hash form. * `longest_flag` - The longest string flag, used to aid configuring help text. **default:** *0*. -Features --------- +Lists +----- + +```ruby +opts = Slop.parse do + on :l=, as: Array +end +# ruby run.rb -l one,two +opts[:l] #=> ["one", "two"] +# ruby run.rb -l one,two -l three +opts[:l] #=> ["one", "two", "three"] +``` -Check out the following wiki pages for more features: +You can also specify a delimiter and limit. + +```ruby +opts = Slop.parse do + on :l=, as: Array, delimiter: ':', limit: 2 +end +# ruby run.rb -l one:two:three +opts[:l] #=> ["one", "two:three"] +``` -* [Ranges](https://github.com/injekt/slop/wiki/Ranges) -* [Auto Create](https://github.com/injekt/slop/wiki/Auto-Create) +Ranges +------ + +```ruby +opts = Slop.parse do + on :r=, as: Range +end +# ruby run.rb -r 1..10 +opts[:r] #=> 1..10 +# ruby run.rb -r 1...10 +opts[:r] #=> 1...10 +# ruby run.rb -r 1-10 +opts[:r] #=> 1..10 +# ruby run.rb -r 1,10 +opts[:r] #=> 1..10 +``` + +Autocreate +---------- + +Slop has an 'autocreate' feature. This feature is intended to create +options on the fly, without having to specify them yourself. In some case, +uses this code could be all you need in your application: + +```ruby +# ruby run.rb --foo bar --baz --name lee +opts = Slop.parse(autocreate: true) +opts.to_hash #=> {:foo=>"bar", :baz=>true, :name=>"lee"} +opts.fetch_option(:name).expects_argument? #=> true +``` Woah woah, why you hating on OptionParser? ------------------------------------------ |