slop 4.3.0 → 4.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 09ca8b84867d657dc875e33dd3d230c4e38f7789
4
- data.tar.gz: 89f3079de8089096383c7a7c10e2ca01b3ae0706
3
+ metadata.gz: 496c3e58ee49a489dc45b3885c49b32367ad0fe5
4
+ data.tar.gz: 7efe7c13f5992f1533486adf452c904f1f4b1981
5
5
  SHA512:
6
- metadata.gz: 340ec84f97161a331d066eec37d45347dfb3368569276df62c214aa9fcf4d7cc5f9b4de442bfc85f02efa0f0492cf32739efe2a1fcac132695d02a165c67bd13
7
- data.tar.gz: 0c3d8e9a7bd21afd3a6748a4b71901dbf4e08c1e6434c731cbabd117441eb7030721d07743ce893caaba92eb6eb2f37e613019de4258a00af0af05950e96eadd
6
+ metadata.gz: 4b1905b9eefaee4c30dd96eb94a6e1740700c2b370e37230869d1d8ccd4679ae6ea5924ae3f72e0f9be97d21c020003ce875c7eb5a4c75f958ddd1da07110ea6
7
+ data.tar.gz: ab9fcf28c51edeece517285cdeb33a82fdf4e1a51e853bf94ae2594ea60d1a405cd665b1161871e5ed43717f5b57f157d30814396d8a53c09d82177f0fa0bc87
@@ -1,6 +1,15 @@
1
1
  Changelog
2
2
  =========
3
3
 
4
+ v4.4.0 (2016-08-15)
5
+ -------------------
6
+
7
+ Features
8
+ * Support parsing arguments prefixed with dashes. #192 (Andrew Clemons)
9
+
10
+ Bug fixes:
11
+ * Retain sort order inside tail sort. #193 (Caio Chassot)
12
+
4
13
  v4.3.0 (2016-03-19)
5
14
  -------------------
6
15
 
@@ -6,7 +6,7 @@ require 'slop/types'
6
6
  require 'slop/error'
7
7
 
8
8
  module Slop
9
- VERSION = '4.3.0'
9
+ VERSION = '4.4.0'
10
10
 
11
11
  # Parse an array of options (defaults to ARGV). Accepts an
12
12
  # optional hash of configuration options and block.
@@ -101,7 +101,7 @@ module Slop
101
101
  str = config[:banner] ? "#{banner}\n" : ""
102
102
  len = longest_flag_length
103
103
 
104
- options.select(&:help?).sort_by(&:tail).each_with_index do |opt, i|
104
+ options.select(&:help?).each_with_index.sort_by{ |o,i| [o.tail, i] }.each do |opt, i|
105
105
  # use the index to fetch an associated separator
106
106
  if sep = separators[i]
107
107
  str << "#{sep}\n"
@@ -43,7 +43,8 @@ module Slop
43
43
 
44
44
  @arguments = strings.dup
45
45
 
46
- pairs.each do |flag, arg|
46
+ pairs.each_with_index do |pair, idx|
47
+ flag, arg = pair
47
48
  break if !flag
48
49
 
49
50
  # ignore everything after '--', flag or not
@@ -54,6 +55,7 @@ module Slop
54
55
 
55
56
  # support `foo=bar`
56
57
  orig_flag = flag.dup
58
+ orig_arg = arg
57
59
  if flag.include?("=")
58
60
  flag, arg = flag.split("=")
59
61
  end
@@ -63,6 +65,12 @@ module Slop
63
65
  # arguments (plus the arg if necessary)
64
66
  # delete argument first while we can find its index.
65
67
  if opt.expects_argument?
68
+
69
+ # if we consumed the argument, remove the next pair
70
+ if orig_arg == opt.value.to_s
71
+ pairs.delete_at(idx + 1)
72
+ end
73
+
66
74
  arguments.each_with_index do |argument, i|
67
75
  if argument == orig_flag && !orig_flag.include?("=")
68
76
  arguments.delete_at(i + 1)
@@ -44,7 +44,7 @@ module Slop
44
44
  # Cast the option argument to an Integer.
45
45
  class IntegerOption < Option
46
46
  def call(value)
47
- value =~ /\A\d+\z/ && value.to_i
47
+ value =~ /\A-?\d+\z/ && value.to_i
48
48
  end
49
49
  end
50
50
  IntOption = IntegerOption
@@ -53,7 +53,7 @@ module Slop
53
53
  class FloatOption < Option
54
54
  def call(value)
55
55
  # TODO: scientific notation, etc.
56
- value =~ /\A\d*\.*\d+\z/ && value.to_f
56
+ value =~ /\A-?\d*\.*\d+\z/ && value.to_f
57
57
  end
58
58
  end
59
59
 
@@ -22,6 +22,27 @@ describe Slop::Parser do
22
22
  assert_equal 123, @result[:port]
23
23
  end
24
24
 
25
+ it "parses arg with leading -" do
26
+ @options.string "-t", "--text"
27
+ @result.parser.parse %w(--name=bob --text --sometext)
28
+ assert_equal "bob", @result[:name]
29
+ assert_equal "--sometext", @result[:text]
30
+ end
31
+
32
+ it "parses negative integer" do
33
+ @options.integer "-p", "--port"
34
+ @result.parser.parse %w(--name=bob --port -123)
35
+ assert_equal "bob", @result[:name]
36
+ assert_equal(-123, @result[:port])
37
+ end
38
+
39
+ it "parses negative float" do
40
+ @options.float "-m", "--multiple"
41
+ @result.parser.parse %w(--name=bob -m -123.987)
42
+ assert_equal "bob", @result[:name]
43
+ assert_equal(-123.987, @result[:multiple])
44
+ end
45
+
25
46
  describe "parsing grouped short flags" do
26
47
  before do
27
48
  @options.bool "-q", "--quiet"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slop
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.3.0
4
+ version: 4.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lee Jarvis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-19 00:00:00.000000000 Z
11
+ date: 2016-08-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake