slop 4.2.1 → 4.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -0
- data/CHANGELOG.md +7 -0
- data/README.md +4 -1
- data/lib/slop.rb +1 -1
- data/lib/slop/options.rb +1 -1
- data/lib/slop/types.rb +6 -2
- data/test/options_test.rb +12 -1
- data/test/types_test.rb +6 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 09ca8b84867d657dc875e33dd3d230c4e38f7789
|
4
|
+
data.tar.gz: 89f3079de8089096383c7a7c10e2ca01b3ae0706
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 340ec84f97161a331d066eec37d45347dfb3368569276df62c214aa9fcf4d7cc5f9b4de442bfc85f02efa0f0492cf32739efe2a1fcac132695d02a165c67bd13
|
7
|
+
data.tar.gz: 0c3d8e9a7bd21afd3a6748a4b71901dbf4e08c1e6434c731cbabd117441eb7030721d07743ce893caaba92eb6eb2f37e613019de4258a00af0af05950e96eadd
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -132,6 +132,9 @@ end
|
|
132
132
|
# --files foo.txt --files bar.rb
|
133
133
|
```
|
134
134
|
|
135
|
+
If you want to disable the built-in string-splitting, set the delimiter to
|
136
|
+
`nil`.
|
137
|
+
|
135
138
|
Custom option types
|
136
139
|
-------------------
|
137
140
|
|
@@ -272,7 +275,7 @@ Upgrading from version 3
|
|
272
275
|
------------------------
|
273
276
|
|
274
277
|
Slop v4 is completely non-backwards compatible. The code has been rewritten
|
275
|
-
from the
|
278
|
+
from the ground up. If you're already using version 3 you *have* to update
|
276
279
|
your code to use version 4. Here's an overview of the more fundamental changes:
|
277
280
|
|
278
281
|
#### No more `instance_eval`
|
data/lib/slop.rb
CHANGED
data/lib/slop/options.rb
CHANGED
@@ -26,7 +26,7 @@ module Slop
|
|
26
26
|
def initialize(**config)
|
27
27
|
@options = []
|
28
28
|
@separators = []
|
29
|
-
@banner = "usage: #{$0} [options]"
|
29
|
+
@banner = config[:banner].is_a?(String) ? config[:banner] : config.fetch(:banner, "usage: #{$0} [options]")
|
30
30
|
@config = DEFAULT_CONFIG.merge(config)
|
31
31
|
@parser = Parser.new(self, @config)
|
32
32
|
|
data/lib/slop/types.rb
CHANGED
@@ -62,7 +62,11 @@ module Slop
|
|
62
62
|
class ArrayOption < Option
|
63
63
|
def call(value)
|
64
64
|
@value ||= []
|
65
|
-
|
65
|
+
if delimiter
|
66
|
+
@value.concat value.split(delimiter, limit)
|
67
|
+
else
|
68
|
+
@value << value
|
69
|
+
end
|
66
70
|
end
|
67
71
|
|
68
72
|
def default_value
|
@@ -70,7 +74,7 @@ module Slop
|
|
70
74
|
end
|
71
75
|
|
72
76
|
def delimiter
|
73
|
-
config
|
77
|
+
config.fetch(:delimiter, ",")
|
74
78
|
end
|
75
79
|
|
76
80
|
def limit
|
data/test/options_test.rb
CHANGED
@@ -55,7 +55,7 @@ describe Slop::Options do
|
|
55
55
|
end
|
56
56
|
|
57
57
|
describe "#to_s" do
|
58
|
-
it "is prefixed with the banner" do
|
58
|
+
it "is prefixed with the default banner" do
|
59
59
|
assert_match(/^usage/, @options.to_s)
|
60
60
|
end
|
61
61
|
|
@@ -82,4 +82,15 @@ describe Slop::Options do
|
|
82
82
|
assert_match(/^ -h, --help/, @options.to_s.lines.last)
|
83
83
|
end
|
84
84
|
end
|
85
|
+
|
86
|
+
describe "custom banner" do
|
87
|
+
it "is prefixed with defined banner" do
|
88
|
+
@options_config = Slop::Options.new({banner: "custom banner"})
|
89
|
+
assert_match(/^custom banner/, @options_config.to_s)
|
90
|
+
end
|
91
|
+
it "banner is disabled" do
|
92
|
+
@options_config = Slop::Options.new({banner: false})
|
93
|
+
assert_match("", @options_config.to_s)
|
94
|
+
end
|
95
|
+
end
|
85
96
|
end
|
data/test/types_test.rb
CHANGED
@@ -67,6 +67,7 @@ describe Slop::ArrayOption do
|
|
67
67
|
before do
|
68
68
|
@options = Slop::Options.new
|
69
69
|
@files = @options.array "--files"
|
70
|
+
@multi = @options.array "-M", delimiter: nil
|
70
71
|
@delim = @options.array "-d", delimiter: ":"
|
71
72
|
@limit = @options.array "-l", limit: 2
|
72
73
|
@result = @options.parse %w(--files foo.txt,bar.rb)
|
@@ -85,6 +86,11 @@ describe Slop::ArrayOption do
|
|
85
86
|
assert_equal %w(foo.txt bar.rb), @result[:files]
|
86
87
|
end
|
87
88
|
|
89
|
+
it "collects multiple option values with no delimiter" do
|
90
|
+
@result.parser.parse %w(-M foo,bar -M bar,qux)
|
91
|
+
assert_equal %w(foo,bar bar,qux), @result[:M]
|
92
|
+
end
|
93
|
+
|
88
94
|
it "can use a custom delimiter" do
|
89
95
|
@result.parser.parse %w(-d foo.txt:bar.rb)
|
90
96
|
assert_equal %w(foo.txt bar.rb), @result[:d]
|
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.3.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:
|
11
|
+
date: 2016-03-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -86,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
86
|
version: '0'
|
87
87
|
requirements: []
|
88
88
|
rubyforge_project:
|
89
|
-
rubygems_version: 2.
|
89
|
+
rubygems_version: 2.5.1
|
90
90
|
signing_key:
|
91
91
|
specification_version: 4
|
92
92
|
summary: Simple Lightweight Option Parsing
|