slop 4.2.0 → 4.2.1
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/.travis.yml +7 -0
- data/CHANGELOG.md +15 -0
- data/README.md +15 -0
- data/lib/slop.rb +1 -1
- data/lib/slop/option.rb +8 -3
- data/lib/slop/parser.rb +11 -3
- data/lib/slop/types.rb +1 -2
- data/test/parser_test.rb +10 -0
- data/test/result_test.rb +3 -0
- data/test/types_test.rb +7 -1
- 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: 46b97913fc755da80d6ce7680b9c62edaa097f18
|
4
|
+
data.tar.gz: e5717f5a2ae612a433f9b602a1fbb0692a75cb77
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80d06a261ab8201470395cc679f0b833ca16f1c340ba6fe4f0a819cbb6fec16b9b41bd86b46d745f27bdbc047a0fbd3b2a5038aaa897f561e657780858437da9
|
7
|
+
data.tar.gz: 102f8d9c8d39db648ef5bb2f9aeae9366ee5b98d83748e8aab076a948ff63699f3fc6ea4eb7371df28958afb9d9e8f97d70a8d7f6fb9ebe477894b07c6fc6ad5
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,21 @@
|
|
1
1
|
Changelog
|
2
2
|
=========
|
3
3
|
|
4
|
+
v4.2.1 (2015-11-25)
|
5
|
+
-------------------
|
6
|
+
|
7
|
+
Features:
|
8
|
+
* Better handling of option names with multiple words. #169 (Tim Rogers)
|
9
|
+
|
10
|
+
Minor enhancements:
|
11
|
+
* add ARGF notes to Arguments (README). #173 (Rick Hull)
|
12
|
+
|
13
|
+
Bug fixes:
|
14
|
+
* Fix arguments removed with option arguments. #182 (Naoki Mizuno)
|
15
|
+
* Fix bug where true is passed to BoolOption block regardless
|
16
|
+
of --no- prefix. #184 (Ben Brady)
|
17
|
+
* only raise MissingArgument if not `default_value`. #163 (Ben Brady)
|
18
|
+
|
4
19
|
v4.2.0 (2015-04-18)
|
5
20
|
-------------------
|
6
21
|
|
data/README.md
CHANGED
@@ -101,6 +101,21 @@ end
|
|
101
101
|
p opts.arguments #=> ["connect", "GET"] # also aliased to `args`
|
102
102
|
```
|
103
103
|
|
104
|
+
This is particularly useful when writing scripts with `ARGF`:
|
105
|
+
|
106
|
+
```ruby
|
107
|
+
opts = Slop.parse do |blah|
|
108
|
+
# ...
|
109
|
+
end
|
110
|
+
|
111
|
+
# make sure sloptions aren't consumed by ARGF
|
112
|
+
ARGV.replace opts.arguments
|
113
|
+
|
114
|
+
ARGF.each { |line|
|
115
|
+
# ...
|
116
|
+
}
|
117
|
+
```
|
118
|
+
|
104
119
|
Arrays
|
105
120
|
------
|
106
121
|
|
data/lib/slop.rb
CHANGED
data/lib/slop/option.rb
CHANGED
@@ -47,11 +47,16 @@ module Slop
|
|
47
47
|
def ensure_call(value)
|
48
48
|
@count += 1
|
49
49
|
|
50
|
-
if value.nil? && expects_argument?
|
51
|
-
|
50
|
+
if value.nil? && expects_argument?
|
51
|
+
if default_value
|
52
|
+
@value = default_value
|
53
|
+
elsif !suppress_errors?
|
54
|
+
raise Slop::MissingArgument.new("missing argument for #{flag}", flags)
|
55
|
+
end
|
56
|
+
else
|
57
|
+
@value = call(value)
|
52
58
|
end
|
53
59
|
|
54
|
-
@value = call(value)
|
55
60
|
block.call(@value) if block.respond_to?(:call)
|
56
61
|
end
|
57
62
|
|
data/lib/slop/parser.rb
CHANGED
@@ -53,6 +53,7 @@ module Slop
|
|
53
53
|
end
|
54
54
|
|
55
55
|
# support `foo=bar`
|
56
|
+
orig_flag = flag.dup
|
56
57
|
if flag.include?("=")
|
57
58
|
flag, arg = flag.split("=")
|
58
59
|
end
|
@@ -60,8 +61,15 @@ module Slop
|
|
60
61
|
if opt = try_process(flag, arg)
|
61
62
|
# since the option was parsed, we remove it from our
|
62
63
|
# arguments (plus the arg if necessary)
|
63
|
-
|
64
|
-
|
64
|
+
# delete argument first while we can find its index.
|
65
|
+
if opt.expects_argument?
|
66
|
+
arguments.each_with_index do |argument, i|
|
67
|
+
if argument == orig_flag && !orig_flag.include?("=")
|
68
|
+
arguments.delete_at(i + 1)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
arguments.delete(orig_flag)
|
65
73
|
end
|
66
74
|
end
|
67
75
|
|
@@ -94,7 +102,7 @@ module Slop
|
|
94
102
|
process(option, arg)
|
95
103
|
elsif flag.start_with?("--no-") && option = matching_option(flag.sub("no-", ""))
|
96
104
|
process(option, false)
|
97
|
-
elsif flag =~ /\A-[^-]/
|
105
|
+
elsif flag =~ /\A-[^-]{2,}/
|
98
106
|
# try and process as a set of grouped short flags. drop(1) removes
|
99
107
|
# the prefixed -, then we add them back to each flag separately.
|
100
108
|
flags = flag.split("").drop(1).map { |f| "-#{f}" }
|
data/lib/slop/types.rb
CHANGED
data/test/parser_test.rb
CHANGED
@@ -66,5 +66,15 @@ describe Slop::Parser do
|
|
66
66
|
@parser.parse %w(-v -- --name lee)
|
67
67
|
assert_equal %w(--name lee), @parser.arguments
|
68
68
|
end
|
69
|
+
|
70
|
+
it "correctly removes the option argument" do
|
71
|
+
@parser.parse %w(lee --name lee lee)
|
72
|
+
assert_equal %w(lee lee), @parser.arguments
|
73
|
+
end
|
74
|
+
|
75
|
+
it "correctly removes options that use =" do
|
76
|
+
@parser.parse %w(lee --name=lee lee)
|
77
|
+
assert_equal %w(lee lee), @parser.arguments
|
78
|
+
end
|
69
79
|
end
|
70
80
|
end
|
data/test/result_test.rb
CHANGED
data/test/types_test.rb
CHANGED
@@ -6,7 +6,9 @@ describe Slop::BoolOption do
|
|
6
6
|
@verbose = @options.bool "--verbose"
|
7
7
|
@quiet = @options.bool "--quiet"
|
8
8
|
@inversed = @options.bool "--inversed", default: true
|
9
|
-
@
|
9
|
+
@bloc = @options.bool("--bloc"){|val| (@bloc_val ||= []) << val}
|
10
|
+
@result = @options.parse %w(--verbose --no-inversed
|
11
|
+
--bloc --no-bloc)
|
10
12
|
end
|
11
13
|
|
12
14
|
it "returns true if used" do
|
@@ -20,6 +22,10 @@ describe Slop::BoolOption do
|
|
20
22
|
it "can be inversed via --no- prefix" do
|
21
23
|
assert_equal false, @result[:inversed]
|
22
24
|
end
|
25
|
+
|
26
|
+
it "will invert the value passed to &block via --no- prefix" do
|
27
|
+
assert_equal [true, false], @bloc_val
|
28
|
+
end
|
23
29
|
end
|
24
30
|
|
25
31
|
describe Slop::IntegerOption do
|
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.2.
|
4
|
+
version: 4.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lee Jarvis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|