slop 3.2.0 → 3.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.md CHANGED
@@ -1,3 +1,10 @@
1
+ 3.3.0 (2012-05-30)
2
+ ------------------
3
+
4
+ * Fix `:as => :count` when using multiple switches.
5
+ * Ensure range typecast allows negative range values.
6
+ * Ignore nil objects send to #parse instead of choking.
7
+
1
8
  3.2.0 (2012-05-15)
2
9
  ------------------
3
10
 
@@ -4,7 +4,7 @@ require 'slop/commands'
4
4
  class Slop
5
5
  include Enumerable
6
6
 
7
- VERSION = '3.2.0'
7
+ VERSION = '3.3.0'
8
8
 
9
9
  # The main Error class, all Exception classes inherit from this class.
10
10
  class Error < StandardError; end
@@ -414,7 +414,7 @@ class Slop
414
414
  #
415
415
  # Returns nothing.
416
416
  def process_item(items, index, &block)
417
- item = items[index]
417
+ return unless item = items[index]
418
418
  option, argument = extract_option(item) if item.start_with?('-')
419
419
 
420
420
  if option
@@ -433,7 +433,7 @@ class Slop
433
433
  elsif option.accepts_optional_argument?
434
434
  argument ||= items.at(index + 1)
435
435
 
436
- if argument && argument !~ /\A--?/
436
+ if argument && argument =~ /\A([^-\-?]|-\d)+/
437
437
  execute_option(option, argument, index, item)
438
438
  else
439
439
  option.call(nil)
@@ -488,7 +488,7 @@ class Slop
488
488
  execute_option(option, argument, index)
489
489
  argument.split('').each do |key|
490
490
  opt = fetch_option(key)
491
- opt.count = 1
491
+ opt.count += 1
492
492
  execute_option(opt, argument, index, key)
493
493
  end
494
494
  end
@@ -46,7 +46,8 @@ class Slop
46
46
  :integer => proc { |v| value_to_integer(v) },
47
47
  :float => proc { |v| value_to_float(v) },
48
48
  :array => proc { |v| v.split(@config[:delimiter], @config[:limit]) },
49
- :range => proc { |v| value_to_range(v) }
49
+ :range => proc { |v| value_to_range(v) },
50
+ :count => proc { |v| @count }
50
51
  }
51
52
 
52
53
  if long && long.size > @slop.config[:longest_flag]
@@ -85,7 +86,10 @@ class Slop
85
86
  # Returns the Object once any type conversions have taken place.
86
87
  def value
87
88
  value = @value.nil? ? config[:default] : @value
88
- return value if [true, false, nil].include?(value)
89
+
90
+ if [true, false, nil].include?(value) && config[:as].to_s != 'count'
91
+ return value
92
+ end
89
93
 
90
94
  type = config[:as]
91
95
  if type.respond_to?(:call)
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'slop'
3
- s.version = '3.2.0'
3
+ s.version = '3.3.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'
@@ -56,7 +56,7 @@ class OptionTest < TestCase
56
56
  opts.on :f=, :as => Integer
57
57
  opts.parse %w'-f 1'
58
58
  assert_equal 1, opts[:f]
59
-
59
+
60
60
  opts = Slop.new(:strict => true) { on :r=, :as => Integer }
61
61
  assert_raises(Slop::InvalidArgumentError) { opts.parse %w/-r abc/ }
62
62
  end
@@ -78,6 +78,7 @@ class OptionTest < TestCase
78
78
  assert_equal (-1..10), option_value(%w/-r -1..10/, :r=, :as => Range)
79
79
  assert_equal (1..-10), option_value(%w/-r 1..-10/, :r=, :as => Range)
80
80
  assert_equal (1..1), option_value(%w/-r 1/, :r=, :as => Range)
81
+ assert_equal (-1..10), option_value(%w/-r -1..10/, :r, :as => Range, :optional_argument => true)
81
82
 
82
83
  opts = Slop.new(:strict => true) { on :r=, :as => Range }
83
84
  assert_raises(Slop::InvalidArgumentError) { opts.parse %w/-r abc/ }
@@ -98,6 +99,12 @@ class OptionTest < TestCase
98
99
  assert_equal 'rab', opt.value
99
100
  end
100
101
 
102
+ test "count type" do
103
+ assert_equal 3, option_value(%w/-c -c -c/, :c, :as => :count)
104
+ assert_equal 0, option_value(%w/-a -b -z/, :c, :as => :count)
105
+ assert_equal 3, option_value(%w/-vvv/, :v, :as => :count)
106
+ end
107
+
101
108
  # end type casting tests
102
109
 
103
110
  test "using a default value as fallback" do
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.2.0
4
+ version: 3.3.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-05-15 00:00:00.000000000 Z
12
+ date: 2012-05-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: &70135352281960 !ruby/object:Gem::Requirement
16
+ requirement: &70279515453400 !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: *70135352281960
24
+ version_requirements: *70279515453400
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: minitest
27
- requirement: &70135352280820 !ruby/object:Gem::Requirement
27
+ requirement: &70279515450800 !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: *70135352280820
35
+ version_requirements: *70279515450800
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: 3008846930636062325
71
+ hash: -452403334270182101
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: 3008846930636062325
80
+ hash: -452403334270182101
81
81
  requirements: []
82
82
  rubyforge_project:
83
83
  rubygems_version: 1.8.11