slop 3.0.0 → 3.0.1

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
+ HEAD
2
+ ----
3
+
4
+ * Ensure tests run green on 1.8.7
5
+ * Ensure `:argument => :optional` works with `:option=` format.
6
+ * Ruby 1.8.7 compat fix (dont chain Enumerable methods!) (Eric Anderson)
7
+
1
8
  3.0.0 (2012-01-24)
2
9
  ------------------
3
10
 
@@ -4,7 +4,7 @@ require 'slop/commands'
4
4
  class Slop
5
5
  include Enumerable
6
6
 
7
- VERSION = '3.0.0'
7
+ VERSION = '3.0.1'
8
8
 
9
9
  # The main Error class, all Exception classes inherit from this class.
10
10
  class Error < StandardError; end
@@ -335,7 +335,7 @@ class Slop
335
335
  heads = options.reject(&:tail?)
336
336
  tails = (options - heads)
337
337
  opts = (heads + tails).select(&:help).map(&:to_s)
338
- optstr = opts.map.with_index { |o, i|
338
+ optstr = opts.each_with_index.map { |o, i|
339
339
  (str = @separators[i + 1]) ? [o, str].join("\n") : o
340
340
  }.join("\n")
341
341
  config[:banner] ? config[:banner] + "\n" + optstr : optstr
@@ -519,10 +519,13 @@ class Slop
519
519
  config[:argument] = true if @config[:arguments]
520
520
  config[:optional_argument] = true if @config[:optional_arguments]
521
521
 
522
- short = extract_short_flag(objects, config)
523
- long = extract_long_flag(objects, config)
524
- desc = objects[0].respond_to?(:to_str) ? objects.shift : nil
525
- config = config.merge!(objects.last) if objects.last.is_a?(Hash)
522
+ if objects.last.is_a?(Hash)
523
+ config = config.merge!(objects.last)
524
+ objects.pop
525
+ end
526
+ short = extract_short_flag(objects, config)
527
+ long = extract_long_flag(objects, config)
528
+ desc = objects[0].respond_to?(:to_str) ? objects.shift : nil
526
529
 
527
530
  Option.new(self, short, long, desc, config, &block)
528
531
  end
@@ -535,7 +538,7 @@ class Slop
535
538
  flag = clean(objects.first)
536
539
 
537
540
  if flag.size == 2 && flag[-1, 1] == '='
538
- config[:argument] = true
541
+ config[:argument] ||= true
539
542
  flag.chop!
540
543
  end
541
544
 
@@ -552,7 +555,7 @@ class Slop
552
555
  def extract_long_flag(objects, config)
553
556
  flag = objects.first.to_s
554
557
  if flag =~ /\A(?:--?)?[a-zA-Z][a-zA-Z0-9_-]+\=?\??\z/
555
- config[:argument] = true if flag[-1, 1] == '='
558
+ config[:argument] ||= true if flag[-1, 1] == '='
556
559
  config[:optional_argument] = true if flag[-2, 2] == '=?'
557
560
  objects.shift
558
561
  clean(flag).sub(/\=\??\z/, '')
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'slop'
3
- s.version = '3.0.0'
3
+ s.version = '3.0.1'
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'
@@ -52,7 +52,10 @@ class OptionTest < TestCase
52
52
  end
53
53
 
54
54
  test "integer type cast" do
55
- assert_equal 1, option_value(%w'-f 1', :f=, :as => Integer)
55
+ opts = Slop.new
56
+ opts.on :f=, :as => Integer
57
+ opts.parse %w'-f 1'
58
+ assert_equal 1, opts[:f]
56
59
  end
57
60
 
58
61
  test "symbol type cast" 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.0.0
4
+ version: 3.0.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: 2012-01-24 00:00:00.000000000 Z
12
+ date: 2012-01-27 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A simple DSL for gathering options and parsing the command line
15
15
  email: lee@jarvis.co