slop 4.4.1 → 4.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -7
- data/CHANGELOG.md +7 -0
- data/lib/slop.rb +1 -1
- data/lib/slop/parser.rb +34 -13
- data/test/parser_test.rb +15 -1
- data/test/result_test.rb +1 -1
- data/test/types_test.rb +2 -2
- metadata +2 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d27e2c3615ec37ec13f7a425eca0bd2095019f4
|
4
|
+
data.tar.gz: e9bd705f261dd6c8f91e53e48c4eb0afaa47b809
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fab6f8d628b08341f2d51f980a75654cb229e1a7a3412e0bc3fc3b19d39a0064adb7461a77a70fd491495e22ae766d464ea7850213320f64b41d72674e68080b
|
7
|
+
data.tar.gz: cca338b3042a5614a673f14a88b50fa990143a31c4c57faeaee3427476468074249ccc803ab7e2a67ad8f9cf31fc6877c87c09c14898ee2725393691edb7bd91
|
data/.travis.yml
CHANGED
@@ -1,18 +1,15 @@
|
|
1
1
|
cache: bundler
|
2
2
|
before_install:
|
3
|
-
- gem
|
3
|
+
- gem install bundler
|
4
4
|
rvm:
|
5
5
|
- 2.0.0
|
6
6
|
- 2.1
|
7
7
|
- 2.2
|
8
|
-
- 2.3.
|
9
|
-
-
|
8
|
+
- 2.3.4
|
9
|
+
- 2.4.1
|
10
|
+
- jruby-9.1.8.0
|
10
11
|
- jruby-head
|
11
12
|
- ruby-head
|
12
|
-
matrix:
|
13
|
-
allow_failures:
|
14
|
-
- rvm: ruby-head
|
15
|
-
- rvm: jruby-head
|
16
13
|
notifications:
|
17
14
|
email:
|
18
15
|
on_success: change
|
data/CHANGELOG.md
CHANGED
data/lib/slop.rb
CHANGED
data/lib/slop/parser.rb
CHANGED
@@ -36,6 +36,9 @@ module Slop
|
|
36
36
|
def parse(strings)
|
37
37
|
reset # reset before every parse
|
38
38
|
|
39
|
+
# ignore everything after "--"
|
40
|
+
strings, ignored_args = partition(strings)
|
41
|
+
|
39
42
|
pairs = strings.each_cons(2).to_a
|
40
43
|
# this ensures we still support the last string being a flag,
|
41
44
|
# otherwise it'll only be used as an argument.
|
@@ -47,12 +50,6 @@ module Slop
|
|
47
50
|
flag, arg = pair
|
48
51
|
break if !flag
|
49
52
|
|
50
|
-
# ignore everything after '--', flag or not
|
51
|
-
if flag == '--'
|
52
|
-
arguments.delete(flag)
|
53
|
-
break
|
54
|
-
end
|
55
|
-
|
56
53
|
# support `foo=bar`
|
57
54
|
orig_flag = flag.dup
|
58
55
|
orig_arg = arg
|
@@ -81,6 +78,8 @@ module Slop
|
|
81
78
|
end
|
82
79
|
end
|
83
80
|
|
81
|
+
@arguments += ignored_args
|
82
|
+
|
84
83
|
Result.new(self).tap do |result|
|
85
84
|
used_options.each { |o| o.finish(result) }
|
86
85
|
end
|
@@ -111,13 +110,7 @@ module Slop
|
|
111
110
|
elsif flag.start_with?("--no-") && option = matching_option(flag.sub("no-", ""))
|
112
111
|
process(option, false)
|
113
112
|
elsif flag =~ /\A-[^-]{2,}/
|
114
|
-
|
115
|
-
# the prefixed -, then we add them back to each flag separately.
|
116
|
-
flags = flag.split("").drop(1).map { |f| "-#{f}" }
|
117
|
-
last = flags.pop
|
118
|
-
|
119
|
-
flags.each { |f| try_process(f, nil) }
|
120
|
-
try_process(last, arg) # send the argument to the last flag
|
113
|
+
try_process_smashed_arg(flag) || try_process_grouped_flags(flag, arg)
|
121
114
|
else
|
122
115
|
if flag.start_with?("-") && !suppress_errors?
|
123
116
|
raise UnknownOption.new("unknown option `#{flag}'", "#{flag}")
|
@@ -125,6 +118,25 @@ module Slop
|
|
125
118
|
end
|
126
119
|
end
|
127
120
|
|
121
|
+
# try and process a flag with a "smashed" argument, e.g.
|
122
|
+
# -nFoo or -i5
|
123
|
+
def try_process_smashed_arg(flag)
|
124
|
+
option = matching_option(flag[0, 2])
|
125
|
+
if option && option.expects_argument?
|
126
|
+
process(option, flag[2..-1])
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
# try and process as a set of grouped short flags. drop(1) removes
|
131
|
+
# the prefixed -, then we add them back to each flag separately.
|
132
|
+
def try_process_grouped_flags(flag, arg)
|
133
|
+
flags = flag.split("").drop(1).map { |f| "-#{f}" }
|
134
|
+
last = flags.pop
|
135
|
+
|
136
|
+
flags.each { |f| try_process(f, nil) }
|
137
|
+
try_process(last, arg) # send the argument to the last flag
|
138
|
+
end
|
139
|
+
|
128
140
|
def suppress_errors?
|
129
141
|
config[:suppress_errors]
|
130
142
|
end
|
@@ -132,5 +144,14 @@ module Slop
|
|
132
144
|
def matching_option(flag)
|
133
145
|
options.find { |o| o.flags.include?(flag) }
|
134
146
|
end
|
147
|
+
|
148
|
+
private def partition(strings)
|
149
|
+
if strings.include?("--")
|
150
|
+
partition_idx = strings.index("--")
|
151
|
+
[strings[0..partition_idx-1], strings[partition_idx+1..-1]]
|
152
|
+
else
|
153
|
+
[strings, []]
|
154
|
+
end
|
155
|
+
end
|
135
156
|
end
|
136
157
|
end
|
data/test/parser_test.rb
CHANGED
@@ -11,8 +11,9 @@ describe Slop::Parser do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
it "ignores everything after --" do
|
14
|
-
@parser.parse %w(-v -- --name lee)
|
14
|
+
@parser.parse %w(-v -- -v --name lee)
|
15
15
|
assert_equal [@verbose], @parser.used_options
|
16
|
+
assert_equal ["-v", "--name", "lee"], @parser.arguments
|
16
17
|
end
|
17
18
|
|
18
19
|
it "parses flag=argument" do
|
@@ -66,6 +67,19 @@ describe Slop::Parser do
|
|
66
67
|
end
|
67
68
|
end
|
68
69
|
|
70
|
+
describe "short flags with arguments" do
|
71
|
+
before do
|
72
|
+
@options.integer "-i"
|
73
|
+
@options.string "-s"
|
74
|
+
end
|
75
|
+
|
76
|
+
it "parses the argument" do
|
77
|
+
@result.parser.parse %w(-i5 -sfoo)
|
78
|
+
assert_equal 5, @result[:i]
|
79
|
+
assert_equal "foo", @result[:s]
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
69
83
|
describe "#used_options" do
|
70
84
|
it "returns all options that were parsed" do
|
71
85
|
assert_equal [@verbose, @name], @parser.used_options
|
data/test/result_test.rb
CHANGED
data/test/types_test.rb
CHANGED
@@ -41,7 +41,7 @@ describe Slop::IntegerOption do
|
|
41
41
|
|
42
42
|
it "returns nil for non-numbers by default" do
|
43
43
|
@result.parser.parse %w(--age hello)
|
44
|
-
|
44
|
+
assert_nil @result[:age]
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
@@ -59,7 +59,7 @@ describe Slop::FloatOption do
|
|
59
59
|
|
60
60
|
it "returns nil for non-numbers by default" do
|
61
61
|
@result.parser.parse %w(--apr hello)
|
62
|
-
|
62
|
+
assert_nil @result[:apr]
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
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.
|
4
|
+
version: 4.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lee Jarvis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-04-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -100,4 +100,3 @@ test_files:
|
|
100
100
|
- test/slop_test.rb
|
101
101
|
- test/test_helper.rb
|
102
102
|
- test/types_test.rb
|
103
|
-
has_rdoc:
|