slop 3.1.1 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGES.md CHANGED
@@ -1,3 +1,8 @@
1
+ 3.2.0 (2012-05-15)
2
+ ------------------
3
+
4
+ * Ensure boolean options appear correctly in `to_hash` output. (#59)
5
+
1
6
  3.1.1 (2012-04-24)
2
7
  ------------------
3
8
 
data/README.md CHANGED
@@ -55,7 +55,7 @@ on '-p', 'password=?', 'Your password'
55
55
  You can also return your options as a Hash:
56
56
 
57
57
  ```ruby
58
- opts.to_hash #=> { :name => 'lee', :verbose => nil, :password => nil }
58
+ opts.to_hash #=> { :name => 'lee', :verbose => true, :password => nil }
59
59
  ```
60
60
 
61
61
  Printing Help
data/lib/slop.rb CHANGED
@@ -4,7 +4,7 @@ require 'slop/commands'
4
4
  class Slop
5
5
  include Enumerable
6
6
 
7
- VERSION = '3.1.1'
7
+ VERSION = '3.2.0'
8
8
 
9
9
  # The main Error class, all Exception classes inherit from this class.
10
10
  class Error < StandardError; end
@@ -441,6 +441,7 @@ class Slop
441
441
  elsif config[:multiple_switches] && argument
442
442
  execute_multiple_switches(option, argument, index)
443
443
  else
444
+ option.value = option.count > 0
444
445
  option.call(nil)
445
446
  end
446
447
  else
data/lib/slop/option.rb CHANGED
@@ -84,8 +84,8 @@ class Slop
84
84
  #
85
85
  # Returns the Object once any type conversions have taken place.
86
86
  def value
87
- value = @value || config[:default]
88
- return if value.nil?
87
+ value = @value.nil? ? config[:default] : @value
88
+ return value if [true, false, nil].include?(value)
89
89
 
90
90
  type = config[:as]
91
91
  if type.respond_to?(:call)
data/slop.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'slop'
3
- s.version = '3.1.1'
3
+ s.version = '3.2.0'
4
4
  s.summary = 'Option gathering made easy'
5
5
  s.description = 'A simple DSL for gathering options and parsing the command line'
6
6
  s.author = 'Lee Jarvis'
data/test/slop_test.rb CHANGED
@@ -157,9 +157,9 @@ class SlopTest < TestCase
157
157
  end
158
158
 
159
159
  test "to_hash()" do
160
- opts = Slop.new { on :foo=; on :bar }
161
- opts.parse(%w'--foo hello --bar')
162
- assert_equal({ :foo => 'hello', :bar => nil }, opts.to_hash)
160
+ opts = Slop.new { on :foo=; on :bar; on :baz; on :zip }
161
+ opts.parse(%w'--foo hello --no-bar --baz')
162
+ assert_equal({ :foo => 'hello', :bar => false, :baz => true, :zip => nil }, opts.to_hash)
163
163
  end
164
164
 
165
165
  test "missing() returning all missing option keys" do
@@ -235,7 +235,7 @@ class SlopTest < TestCase
235
235
  opts = Slop.new { on :foo=; on :bar; on :baz }
236
236
  opts.parse %w' --foo hello --bar '
237
237
  assert_equal 'hello', opts[:foo]
238
- assert_nil opts[:bar]
238
+ assert_equal true, opts[:bar]
239
239
  assert_nil opts[:baz]
240
240
  end
241
241
 
@@ -263,6 +263,13 @@ class SlopTest < TestCase
263
263
  assert opts.foo_bar?
264
264
  end
265
265
 
266
+ test "supporting underscore" do
267
+ opts = Slop.new { on :foo_bar= }
268
+ opts.parse %w' --foo_bar baz '
269
+ assert_equal 'baz', opts[:foo_bar]
270
+ assert opts.foo_bar?
271
+ end
272
+
266
273
  test "parsing an optspec and building options" do
267
274
  optspec = <<-SPEC
268
275
  ruby foo.rb [options]
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: 3.1.1
4
+ version: 3.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-24 00:00:00.000000000 Z
12
+ date: 2012-05-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: &70218307194080 !ruby/object:Gem::Requirement
16
+ requirement: &70135352281960 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70218307194080
24
+ version_requirements: *70135352281960
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: minitest
27
- requirement: &70218307193220 !ruby/object:Gem::Requirement
27
+ requirement: &70135352280820 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70218307193220
35
+ version_requirements: *70135352280820
36
36
  description: A simple DSL for gathering options and parsing the command line
37
37
  email: lee@jarvis.co
38
38
  executables: []
@@ -68,7 +68,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
68
68
  version: '0'
69
69
  segments:
70
70
  - 0
71
- hash: 2699776983474295895
71
+ hash: 3008846930636062325
72
72
  required_rubygems_version: !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
@@ -77,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
77
  version: '0'
78
78
  segments:
79
79
  - 0
80
- hash: 2699776983474295895
80
+ hash: 3008846930636062325
81
81
  requirements: []
82
82
  rubyforge_project:
83
83
  rubygems_version: 1.8.11