slop 4.6.2 → 4.7.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 +5 -5
- data/.travis.yml +11 -2
- data/CHANGELOG.md +35 -24
- data/README.md +12 -14
- data/lib/slop.rb +1 -1
- data/lib/slop/error.rb +3 -2
- data/lib/slop/options.rb +1 -1
- data/lib/slop/parser.rb +8 -1
- data/lib/slop/result.rb +21 -7
- data/test/options_test.rb +6 -0
- data/test/parser_test.rb +6 -0
- data/test/result_test.rb +25 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 125a7e982b88caf3675166359579515c0af86540002d463042c336c45de8f310
|
4
|
+
data.tar.gz: a0518f68ab2a02cb7cdcdc18fbf0fb9134eac55dc903b1486fa569e66b15a18a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 463bd12f9ab37a1f27ebca2bdb98954d69f3160bb64d6b8d813a319f66bde91f07c9002ebfd5267277fbbe87bfb20dc50faa0b74e7478ffe3e1acad049dd765e
|
7
|
+
data.tar.gz: 0c5fa72e533dbdf3ff4bfc1f1f5c7c0944aa4e8f1afc41b41ffe7b8c29807be11b111d5f2c218a3f68034dc65243ea527cad4f0a27af56a5fefddce6e20550ba
|
data/.travis.yml
CHANGED
@@ -1,13 +1,22 @@
|
|
1
1
|
cache: bundler
|
2
2
|
before_install:
|
3
|
-
-
|
3
|
+
- |
|
4
|
+
export RVM_CURRENT=`rvm current|cut -c6-8`
|
5
|
+
if [ "${RVM_CURRENT}" = "2.0" ] || \
|
6
|
+
[ "${RVM_CURRENT}" = "2.1" ] || \
|
7
|
+
[ "${RVM_CURRENT}" = "2.2" ]; then
|
8
|
+
gem install bundler -v '< 2'
|
9
|
+
fi
|
10
|
+
|
4
11
|
rvm:
|
5
12
|
- 2.0.0
|
6
13
|
- 2.1
|
7
14
|
- 2.2
|
8
15
|
- 2.3.4
|
9
16
|
- 2.4.1
|
10
|
-
-
|
17
|
+
- 2.5.3
|
18
|
+
- 2.6.0
|
19
|
+
- jruby-9.2.5.0
|
11
20
|
- jruby-head
|
12
21
|
- ruby-head
|
13
22
|
notifications:
|
data/CHANGELOG.md
CHANGED
@@ -1,31 +1,42 @@
|
|
1
1
|
Changelog
|
2
2
|
=========
|
3
3
|
|
4
|
+
v4.7.0 (2019-06-29)
|
5
|
+
-------------------
|
6
|
+
|
7
|
+
Features:
|
8
|
+
* Add `Slop::Result#fetch`. It returns the value of given option, or raises an error if given option is not present. [#232](https://github.com/leejarvis/slop/pull/232) ([Giovanni Benussi](https://github.com/giovannibenussi))
|
9
|
+
* Adding a separator without passing any arguments now creates a separator with the empty string. [#238](https://github.com/leejarvis/slop/pull/238) ([Teemu Matilainen](https://github.com/tmatilai))
|
10
|
+
Bug fixes
|
11
|
+
* Ensure non-string option types have their flags consumed properly [#241] (Sutou Kouhei)
|
12
|
+
|
13
|
+
|
4
14
|
v4.6.2 (2018-03-12)
|
15
|
+
-------------------
|
5
16
|
|
6
17
|
Bug fixes/Enhancements
|
7
|
-
* Fix equals character (=) being parsed incorrectly in some cases. #226
|
18
|
+
* Fix equals character (=) being parsed incorrectly in some cases. [#226](https://github.com/leejarvis/slop/issues/226)
|
8
19
|
|
9
20
|
v4.6.1 (2017-11-20)
|
10
21
|
-------------------
|
11
22
|
|
12
23
|
Bug fixes/Enhancements
|
13
|
-
* Fix separator so it doesn't mutate user data. #223 (Marc-André Lafortune)
|
24
|
+
* Fix separator so it doesn't mutate user data. [#223](https://github.com/leejarvis/slop/issues/223) (Marc-André Lafortune)
|
14
25
|
* Add additional tests for `Options#separator` and fix issue where
|
15
|
-
the last separator was ignored. #222
|
26
|
+
the last separator was ignored. [#222](https://github.com/leejarvis/slop/issues/222)
|
16
27
|
|
17
28
|
v4.6.0 (2017-10-06)
|
18
29
|
-------------------
|
19
30
|
|
20
31
|
Features
|
21
|
-
* Add support for required options. #218 (William Woodruff)
|
32
|
+
* Add support for required options. [#218](https://github.com/leejarvis/slop/issues/218) (William Woodruff)
|
22
33
|
|
23
34
|
v4.5.0 (2017-05-22)
|
24
35
|
-------------------
|
25
36
|
|
26
37
|
Features:
|
27
38
|
* Added config option to avoid translating flags-with-dashes into
|
28
|
-
underscores. #206 (@lbriais)
|
39
|
+
underscores. [#206](https://github.com/leejarvis/slop/issues/206) (@lbriais)
|
29
40
|
|
30
41
|
v4.4.3 (2017-05-02)
|
31
42
|
-------------------
|
@@ -37,73 +48,73 @@ v4.4.2 (2017-04-29)
|
|
37
48
|
-------------------
|
38
49
|
|
39
50
|
Bug fixes:
|
40
|
-
* Fix support for parsing -x5 or -nfoo. #199
|
41
|
-
* Fix removing arguments after `--`. #194
|
51
|
+
* Fix support for parsing -x5 or -nfoo. [#199](https://github.com/leejarvis/slop/issues/199)
|
52
|
+
* Fix removing arguments after `--`. [#194](https://github.com/leejarvis/slop/issues/194)
|
42
53
|
|
43
54
|
v4.4.1 (2016-08-21)
|
44
55
|
-------------------
|
45
56
|
|
46
57
|
Bug fixes:
|
47
|
-
* Handle bad constant names in `Slop.option_defined?`. #198
|
58
|
+
* Handle bad constant names in `Slop.option_defined?`. [#198](https://github.com/leejarvis/slop/issues/198)
|
48
59
|
(Ellen Marie Dash)
|
49
60
|
|
50
61
|
v4.4.0 (2016-08-15)
|
51
62
|
-------------------
|
52
63
|
|
53
64
|
Features
|
54
|
-
* Support parsing arguments prefixed with dashes. #192 (Andrew Clemons)
|
65
|
+
* Support parsing arguments prefixed with dashes. [#192](https://github.com/leejarvis/slop/issues/192) (Andrew Clemons)
|
55
66
|
|
56
67
|
Bug fixes:
|
57
|
-
* Retain sort order inside tail sort. #193 (Caio Chassot)
|
68
|
+
* Retain sort order inside tail sort. [#193](https://github.com/leejarvis/slop/issues/193) (Caio Chassot)
|
58
69
|
|
59
70
|
v4.3.0 (2016-03-19)
|
60
71
|
-------------------
|
61
72
|
|
62
73
|
Features
|
63
|
-
* Allow disabling array delimiter. #189 (Mike Pastore)
|
64
|
-
* Allow passing custom banner as config. #191 (Philip Rees)
|
74
|
+
* Allow disabling array delimiter. [#189](https://github.com/leejarvis/slop/issues/189) (Mike Pastore)
|
75
|
+
* Allow passing custom banner as config. [#191](https://github.com/leejarvis/slop/issues/191) (Philip Rees)
|
65
76
|
|
66
77
|
v4.2.1 (2015-11-25)
|
67
78
|
-------------------
|
68
79
|
|
69
80
|
Features:
|
70
|
-
* Better handling of option names with multiple words. #169 (Tim Rogers)
|
81
|
+
* Better handling of option names with multiple words. [#169](https://github.com/leejarvis/slop/issues/169) (Tim Rogers)
|
71
82
|
|
72
83
|
Minor enhancements:
|
73
|
-
* add ARGF notes to Arguments (README). #173 (Rick Hull)
|
84
|
+
* add ARGF notes to Arguments (README). [#173](https://github.com/leejarvis/slop/issues/173) (Rick Hull)
|
74
85
|
|
75
86
|
Bug fixes:
|
76
|
-
* Fix arguments removed with option arguments. #182 (Naoki Mizuno)
|
87
|
+
* Fix arguments removed with option arguments. [#182](https://github.com/leejarvis/slop/issues/182) (Naoki Mizuno)
|
77
88
|
* Fix bug where true is passed to BoolOption block regardless
|
78
|
-
of --no- prefix. #184 (Ben Brady)
|
79
|
-
* only raise MissingArgument if not `default_value`. #163 (Ben Brady)
|
89
|
+
of --no- prefix. [#184](https://github.com/leejarvis/slop/issues/184) (Ben Brady)
|
90
|
+
* only raise MissingArgument if not `default_value`. [#163](https://github.com/leejarvis/slop/issues/163) (Ben Brady)
|
80
91
|
|
81
92
|
v4.2.0 (2015-04-18)
|
82
93
|
-------------------
|
83
94
|
|
84
95
|
Features:
|
85
|
-
* Support for Regexp option type #167 (Laurent Arnoud)
|
96
|
+
* Support for Regexp option type [#167](https://github.com/leejarvis/slop/issues/167) (Laurent Arnoud)
|
86
97
|
* Support prefixed `--no-` for explicitly setting boolean options
|
87
|
-
to `false` #168
|
88
|
-
* Better handling of flags with multiple words #169 (Tim Rogers)
|
98
|
+
to `false` [#168](https://github.com/leejarvis/slop/issues/168)
|
99
|
+
* Better handling of flags with multiple words [#169](https://github.com/leejarvis/slop/issues/169) (Tim Rogers)
|
89
100
|
|
90
101
|
v4.1.0 (2015-04-18)
|
91
102
|
-------------------
|
92
103
|
|
93
104
|
Features:
|
94
|
-
* Support for FloatOption #156 (Rick Hull)
|
105
|
+
* Support for FloatOption [#156](https://github.com/leejarvis/slop/issues/156) (Rick Hull)
|
95
106
|
* Support for `limit` config to ArrayOption.
|
96
107
|
* Support for `tail` config to add options to the bottom of
|
97
108
|
the help text.
|
98
|
-
* Add explicit setter (#[]=) to Result class. #162
|
109
|
+
* Add explicit setter (#[]=) to Result class. [#162](https://github.com/leejarvis/slop/issues/162)
|
99
110
|
* Implement flag gettings for UnknownOption and MissingArgument
|
100
|
-
error classes. #165 (sigurdsvela)
|
111
|
+
error classes. [#165](https://github.com/leejarvis/slop/issues/165) (sigurdsvela)
|
101
112
|
|
102
113
|
Minor enhancements:
|
103
114
|
* Reset parser every time `parse` is called.
|
104
115
|
|
105
116
|
Bug fixes:
|
106
|
-
* Remove "--" from unprocessed arguments #157 (David Rodríguez).
|
117
|
+
* Remove "--" from unprocessed arguments [#157](https://github.com/leejarvis/slop/issues/157) (David Rodríguez).
|
107
118
|
|
108
119
|
v4.0.0 (2014-12-27)
|
109
120
|
-------------------
|
data/README.md
CHANGED
@@ -276,16 +276,14 @@ Commands
|
|
276
276
|
--------
|
277
277
|
|
278
278
|
As of version 4, Slop does not have built in support for git-style subcommands.
|
279
|
-
You can use version 3 of Slop (see `v3` branch).
|
280
|
-
external libraries released soon that wrap around Slop to provide support for
|
281
|
-
this feature. I'll update this document when that happens.
|
279
|
+
You can use version 3 of Slop (see `v3` branch).
|
282
280
|
|
283
281
|
Upgrading from version 3
|
284
282
|
------------------------
|
285
283
|
|
286
|
-
Slop v4 is
|
287
|
-
|
288
|
-
|
284
|
+
Slop v4 is not backwards compatible. The code has been completely rewritten.
|
285
|
+
If you're already using version 3 you *have* to update your code to use version 4.
|
286
|
+
Here's an overview of the large changes:
|
289
287
|
|
290
288
|
#### No more `instance_eval`
|
291
289
|
|
@@ -327,22 +325,22 @@ See the custom types section of the document.
|
|
327
325
|
|
328
326
|
#### No more trailing `=`
|
329
327
|
|
330
|
-
Instead, the "does this option expect an argument" question is answered by
|
328
|
+
Instead, the "does this option expect an argument?" question is answered by
|
331
329
|
the option type (i.e `on` and `bool` options do not expect arguments, all
|
332
|
-
others do. They handle type conversion, too.
|
330
|
+
others do). They handle type conversion, too.
|
333
331
|
|
334
332
|
#### Hyphens are required
|
335
333
|
|
336
334
|
This was a hard decision to make, but you must provide prefixed hyphens when
|
337
|
-
declaring your flags. This
|
338
|
-
ambiguous, which leads to less error prone code. It also means you
|
339
|
-
support single hyphen prefix for a long flag, i.e `-hostname` which
|
340
|
-
could not do before. It also
|
341
|
-
|
335
|
+
declaring your flags. This improves the implementation nicer and makes things
|
336
|
+
much less ambiguous, which leads to less error prone code. It also means you
|
337
|
+
can easily support single hyphen prefix for a long flag, i.e `-hostname` which
|
338
|
+
you could not do before. It also means you can provide infinite flag aliases:
|
339
|
+
`o.string '-f', '-x', '--foo', '--bar', 'this is insane'`
|
342
340
|
|
343
341
|
#### Strict is now on by default
|
344
342
|
|
345
|
-
v3 had a `strict` option. v4 has no such option
|
343
|
+
v3 had a `strict` option. v4 has no such option. To suppress errors you can
|
346
344
|
instead provide the `suppress_errors: true` option to Slop.
|
347
345
|
|
348
346
|
#### No more parse!
|
data/lib/slop.rb
CHANGED
data/lib/slop/error.rb
CHANGED
@@ -22,8 +22,9 @@ module Slop
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
# Raised when an unknown option is parsed
|
26
|
-
#
|
25
|
+
# Raised when an unknown option is parsed or when trying to fetch an
|
26
|
+
# unexisting option via `Slop::Result#fetch`.
|
27
|
+
# Suppress with the `suppress_errors` config option.
|
27
28
|
class UnknownOption < Error
|
28
29
|
attr_reader :flag
|
29
30
|
|
data/lib/slop/options.rb
CHANGED
data/lib/slop/parser.rb
CHANGED
@@ -64,7 +64,7 @@ module Slop
|
|
64
64
|
if opt.expects_argument?
|
65
65
|
|
66
66
|
# if we consumed the argument, remove the next pair
|
67
|
-
if
|
67
|
+
if consume_next_argument?(orig_flag)
|
68
68
|
pairs.delete_at(idx + 1)
|
69
69
|
end
|
70
70
|
|
@@ -106,6 +106,13 @@ module Slop
|
|
106
106
|
|
107
107
|
private
|
108
108
|
|
109
|
+
def consume_next_argument?(flag)
|
110
|
+
return false if flag.include?("=")
|
111
|
+
return true if flag.start_with?("--")
|
112
|
+
return true if /\A-[a-zA-Z]\z/ === flag
|
113
|
+
false
|
114
|
+
end
|
115
|
+
|
109
116
|
# We've found an option, process and return it
|
110
117
|
def process(option, arg)
|
111
118
|
option.ensure_call(arg)
|
data/lib/slop/result.rb
CHANGED
@@ -14,12 +14,23 @@ module Slop
|
|
14
14
|
@options = parser.options
|
15
15
|
end
|
16
16
|
|
17
|
-
# Returns an
|
17
|
+
# Returns an option's value, nil if the option does not exist.
|
18
18
|
def [](flag)
|
19
19
|
(o = option(flag)) && o.value
|
20
20
|
end
|
21
21
|
alias get []
|
22
22
|
|
23
|
+
# Returns an option's value, raises UnknownOption if the option does not exist.
|
24
|
+
def fetch(flag)
|
25
|
+
o = option(flag)
|
26
|
+
if o.nil?
|
27
|
+
cleaned_key = clean_key(flag)
|
28
|
+
raise UnknownOption.new("option not found: '#{cleaned_key}'", "#{cleaned_key}")
|
29
|
+
else
|
30
|
+
o.value
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
23
34
|
# Set the value for an option. Raises an ArgumentError if the option
|
24
35
|
# does not exist.
|
25
36
|
def []=(flag, value)
|
@@ -33,13 +44,8 @@ module Slop
|
|
33
44
|
|
34
45
|
# Returns an Option if it exists. Ignores any prefixed hyphens.
|
35
46
|
def option(flag)
|
36
|
-
cleaned = -> (f) do
|
37
|
-
key = f.to_s.sub(/\A--?/, '')
|
38
|
-
key = key.tr '-', '_' if parser.config[:underscore_flags]
|
39
|
-
key.to_sym
|
40
|
-
end
|
41
47
|
options.find do |o|
|
42
|
-
o.flags.any? { |f|
|
48
|
+
o.flags.any? { |f| clean_key(f) == clean_key(flag) }
|
43
49
|
end
|
44
50
|
end
|
45
51
|
|
@@ -90,5 +96,13 @@ module Slop
|
|
90
96
|
def to_s(**opts)
|
91
97
|
options.to_s(**opts)
|
92
98
|
end
|
99
|
+
|
100
|
+
private
|
101
|
+
|
102
|
+
def clean_key(key)
|
103
|
+
key = key.to_s.sub(/\A--?/, '')
|
104
|
+
key = key.tr '-', '_' if parser.config[:underscore_flags]
|
105
|
+
key.to_sym
|
106
|
+
end
|
93
107
|
end
|
94
108
|
end
|
data/test/options_test.rb
CHANGED
@@ -64,6 +64,12 @@ describe Slop::Options do
|
|
64
64
|
@options.separator("foo".freeze)
|
65
65
|
@options.separator("bar".freeze)
|
66
66
|
end
|
67
|
+
|
68
|
+
it "defaults to empty string" do
|
69
|
+
@options.separator
|
70
|
+
|
71
|
+
assert_equal [""], @options.separators
|
72
|
+
end
|
67
73
|
end
|
68
74
|
|
69
75
|
describe "#method_missing" do
|
data/test/parser_test.rb
CHANGED
@@ -35,6 +35,12 @@ describe Slop::Parser do
|
|
35
35
|
assert_equal "--sometext", @result[:text]
|
36
36
|
end
|
37
37
|
|
38
|
+
it "parses regexp arg with leading -" do
|
39
|
+
@options.regexp "--pattern"
|
40
|
+
@result.parser.parse %w(--pattern -x)
|
41
|
+
assert_equal(/-x/, @result[:pattern])
|
42
|
+
end
|
43
|
+
|
38
44
|
it "parses negative integer" do
|
39
45
|
@options.integer "-p", "--port"
|
40
46
|
@result.parser.parse %w(--name=bob --port -123)
|
data/test/result_test.rb
CHANGED
@@ -62,6 +62,31 @@ describe Slop::Result do
|
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
+
describe "#fetch" do
|
66
|
+
it "returns an options value" do
|
67
|
+
assert_equal "lee", @result.fetch("--name")
|
68
|
+
end
|
69
|
+
|
70
|
+
it "raises Slop::UnknownOption when an option does not exists" do
|
71
|
+
e = assert_raises(Slop::UnknownOption) { @result.fetch("--unexisting") }
|
72
|
+
assert_equal "option not found: 'unexisting'", e.message
|
73
|
+
end
|
74
|
+
|
75
|
+
it "returns the default value of an option when a value is not provided" do
|
76
|
+
@options.string("--foo", default: "bar")
|
77
|
+
@result.parser.parse %w(--foo)
|
78
|
+
|
79
|
+
assert_equal 'bar', @result.fetch('foo')
|
80
|
+
end
|
81
|
+
|
82
|
+
it "returns nil when an option is not provided and it does not have a default value" do
|
83
|
+
@options.string("--hello")
|
84
|
+
@result.parser.parse %w()
|
85
|
+
|
86
|
+
assert_nil @result.fetch('hello')
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
65
90
|
describe "#[]=" do
|
66
91
|
it "sets an options value" do
|
67
92
|
assert_equal "lee", @result["name"]
|
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.7.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: 2019-06-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -87,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
87
87
|
version: '0'
|
88
88
|
requirements: []
|
89
89
|
rubyforge_project:
|
90
|
-
rubygems_version: 2.
|
90
|
+
rubygems_version: 2.7.6
|
91
91
|
signing_key:
|
92
92
|
specification_version: 4
|
93
93
|
summary: Simple Lightweight Option Parsing
|