README.md in slop-1.9.1 vs README.md in slop-2.0.0
- old
+ new
@@ -37,11 +37,11 @@
[Creating Options](https://github.com/injekt/slop/wiki/Creating-Options)
wiki page.
You can also return your options as a Hash
- opts.to_hash #=> {'name' => 'Lee Jarvis', 'verbose' => true, 'age' => nil, 'sex' => 'male'}
+ opts.to_hash #=> {:name => 'Lee Jarvis', :verbose => true, :age => nil, :sex => 'male'}
If you want some pretty output for the user to see your options, you can just
send the Slop object to `puts` or use the `help` method.
puts opts
@@ -81,11 +81,11 @@
Parsing
-------
Slop's pretty good at parsing, let's take a look at what it'll extract for you
- Slop.parse do
+ Slop.parse(:multiple_switches => false) do
on 's', 'server', true
on 'p', 'port', true, :as => :integer
on 'username', true, :matches => /[^a-zA-Z]+$/
on 'password', true
end
@@ -95,14 +95,14 @@
-s ftp://foobar.com -p1234 --username=FooBar --password 'hello there'
Here's what we'll get back
{
- :server=>"ftp://foobar.com",
- :port=>1234,
- :username=>"FooBar",
- :password=>"hello there"
+ :server => "ftp://foobar.com",
+ :port => 1234,
+ :username => "FooBar",
+ :password => "hello there"
}
Events
------
@@ -158,26 +158,33 @@
Short Switches
--------------
Want to enable multiple switches at once like rsync does? By default Slop will
-parse `-abcd` as the option `a` with the argument `bcd`, this can be disabled
-by passing the `:multiple_switches` option to a new Slop object.
+parse `-abc` as the options `a` `b` and `c` and set their values to true. If
+you would like to disable this, you can pass `multiple_switches => false` to
+a new Slop object. In which case Slop will then parse `-fbar` as the option
+`f` with the argument value `bar`.
- opts = Slop.new(:strict, :multiple_switches) do
+ Slop.parse do
on :a, 'First switch'
on :b, 'Second switch'
on :c, 'Third switch'
end
- opts.parse
-
# Using `-ac`
opts[:a] #=> true
opts[:b] #=> false
opts[:c] #=> true
+ Slop.parse(:multiple_switches => false) do
+ on :a, 'Some switch', true
+ end
+
+ # Using `ahello`
+ opts[:a] #=> 'hello'
+
Lists
-----
You can of course also parse lists into options. Here's how:
@@ -243,6 +250,6 @@
opts = Slop.parse do
on :n, :name, 'Your name', true
on :a, :age, 'Your age', true, :as => :int
end
- opts.to_hash(true) #=> { :name => 'lee', :age => 105 }
+ opts.to_hash #=> { :name => 'lee', :age => 105 }
\ No newline at end of file