slop 2.3.0 → 2.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.md +9 -2
- data/README.md +4 -4
- data/lib/slop.rb +9 -9
- data/slop.gemspec +1 -1
- data/test/option_test.rb +8 -0
- metadata +2 -2
data/CHANGES.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
|
-
2.3.
|
2
|
-
|
1
|
+
2.3.1 (2011-11-11)
|
2
|
+
------------------
|
3
|
+
|
4
|
+
* Return `nil` for any options using casting which don't expect arguments (#33)
|
5
|
+
* Fix parenthesis warning on 1.8.7 (@shevegen)
|
6
|
+
* Ensure long argument is a string before attempting to use `#[]` method on it
|
7
|
+
|
8
|
+
2.3.0 (2011-11-04)
|
9
|
+
------------------
|
3
10
|
|
4
11
|
* Allow flags to have suffixed `=` char for options which accept an argument
|
5
12
|
|
data/README.md
CHANGED
@@ -89,9 +89,9 @@ end
|
|
89
89
|
Shortcut:
|
90
90
|
|
91
91
|
```ruby
|
92
|
-
Slop.
|
93
|
-
|
94
|
-
|
92
|
+
Slop.new :help => true
|
93
|
+
# or
|
94
|
+
Slop.new :help
|
95
95
|
```
|
96
96
|
|
97
97
|
Parsing
|
@@ -103,7 +103,7 @@ Slop's pretty good at parsing, let's take a look at what it'll extract for you
|
|
103
103
|
Slop.parse(:multiple_switches => false) do
|
104
104
|
on 's', 'server='
|
105
105
|
on 'p', 'port=', :as => :integer
|
106
|
-
on 'username=', :matches =>
|
106
|
+
on 'username=', :matches => /^[a-zA-Z]+$/
|
107
107
|
on 'password='
|
108
108
|
end
|
109
109
|
```
|
data/lib/slop.rb
CHANGED
@@ -2,7 +2,7 @@ class Slop
|
|
2
2
|
include Enumerable
|
3
3
|
|
4
4
|
# @return [String] The current version string
|
5
|
-
VERSION = '2.3.
|
5
|
+
VERSION = '2.3.1'
|
6
6
|
|
7
7
|
# Slops standard Error class. All exception classes should
|
8
8
|
# inherit from this class
|
@@ -152,12 +152,12 @@ class Slop
|
|
152
152
|
return if value.nil?
|
153
153
|
|
154
154
|
case @argument_type
|
155
|
-
when 'array'; @argument_value
|
156
|
-
when 'range'; value_to_range value
|
157
|
-
when 'float'; value.to_s.to_f
|
158
|
-
when 'string', 'str'; value.to_s
|
159
|
-
when 'symbol', 'sym'; value.to_s.to_sym
|
160
|
-
when 'integer', 'int'; value.to_s.to_i
|
155
|
+
when 'array'; @argument_value unless !expects_argument?
|
156
|
+
when 'range'; value_to_range value unless !expects_argument?
|
157
|
+
when 'float'; value.to_s.to_f unless !expects_argument?
|
158
|
+
when 'string', 'str'; value.to_s unless !expects_argument?
|
159
|
+
when 'symbol', 'sym'; value.to_s.to_sym unless !expects_argument?
|
160
|
+
when 'integer', 'int'; value.to_s.to_i unless !expects_argument?
|
161
161
|
else
|
162
162
|
value
|
163
163
|
end
|
@@ -1009,14 +1009,14 @@ class Slop
|
|
1009
1009
|
extras[:optional] = help[0, 1] == '[' && help[-1, 1] == ']'
|
1010
1010
|
extras[:help] = help
|
1011
1011
|
elsif not boolean and long.to_s =~ /\A(?:--?)?[a-zA-Z][a-zA-Z0-9_-]+\=?\z/
|
1012
|
-
extras[:argument] = true if long[-1, 1] == '='
|
1012
|
+
extras[:argument] = true if long.to_s[-1, 1] == '='
|
1013
1013
|
options.push args.shift.to_s.sub(/\A--?/, '').sub(/\=\z/, '')
|
1014
1014
|
else
|
1015
1015
|
options.push nil
|
1016
1016
|
end
|
1017
1017
|
|
1018
1018
|
options.push args.first.respond_to?(:to_sym) ? args.shift : nil
|
1019
|
-
options.push
|
1019
|
+
options.push((@arguments || extras[:argument]) ? true : (args.shift ? true : false))
|
1020
1020
|
options.push extras
|
1021
1021
|
end
|
1022
1022
|
end
|
data/slop.gemspec
CHANGED
data/test/option_test.rb
CHANGED
@@ -87,6 +87,14 @@ class OptionTest < TestCase
|
|
87
87
|
assert_equal 3, option_value(%w/-vvv/, :v, :verbose, :as => :count)
|
88
88
|
end
|
89
89
|
|
90
|
+
test 'casting should return nil for optionless arguments' do
|
91
|
+
assert_equal nil, option_value(%w/-i/, :i, :as => :int)
|
92
|
+
assert_equal nil, option_value(%w/-i/, :i, :as => :str)
|
93
|
+
assert_equal nil, option_value(%w/-i/, :i, :as => :float)
|
94
|
+
assert_equal nil, option_value(%w/-i/, :i, :as => :array)
|
95
|
+
assert_equal nil, option_value(%w/-i/, :i, :as => :range)
|
96
|
+
end
|
97
|
+
|
90
98
|
test 'ranges' do
|
91
99
|
assert_equal (1..10), option_value(%w/-r 1..10/, :r, true, :as => Range)
|
92
100
|
assert_equal (1..10), option_value(%w/-r 1-10/, :r, true, :as => Range)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.3.
|
4
|
+
version: 2.3.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-11-
|
12
|
+
date: 2011-11-11 00:00:00.000000000Z
|
13
13
|
dependencies: []
|
14
14
|
description: A simple DSL for gathering options and parsing the command line
|
15
15
|
email: lee@jarvis.co
|