slop 4.3.0 → 4.4.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/lib/slop.rb +1 -1
- data/lib/slop/options.rb +1 -1
- data/lib/slop/parser.rb +9 -1
- data/lib/slop/types.rb +2 -2
- data/test/parser_test.rb +21 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 496c3e58ee49a489dc45b3885c49b32367ad0fe5
|
4
|
+
data.tar.gz: 7efe7c13f5992f1533486adf452c904f1f4b1981
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b1905b9eefaee4c30dd96eb94a6e1740700c2b370e37230869d1d8ccd4679ae6ea5924ae3f72e0f9be97d21c020003ce875c7eb5a4c75f958ddd1da07110ea6
|
7
|
+
data.tar.gz: ab9fcf28c51edeece517285cdeb33a82fdf4e1a51e853bf94ae2594ea60d1a405cd665b1161871e5ed43717f5b57f157d30814396d8a53c09d82177f0fa0bc87
|
data/CHANGELOG.md
CHANGED
@@ -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
|
|
data/lib/slop.rb
CHANGED
data/lib/slop/options.rb
CHANGED
@@ -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
|
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"
|
data/lib/slop/parser.rb
CHANGED
@@ -43,7 +43,8 @@ module Slop
|
|
43
43
|
|
44
44
|
@arguments = strings.dup
|
45
45
|
|
46
|
-
pairs.
|
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)
|
data/lib/slop/types.rb
CHANGED
@@ -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
|
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
|
56
|
+
value =~ /\A-?\d*\.*\d+\z/ && value.to_f
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
data/test/parser_test.rb
CHANGED
@@ -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.
|
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-
|
11
|
+
date: 2016-08-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|