slop 4.4.3 → 4.5.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 +7 -0
- data/lib/slop.rb +1 -1
- data/lib/slop/option.rb +9 -1
- data/lib/slop/options.rb +4 -3
- data/lib/slop/result.rb +5 -1
- data/test/option_test.rb +4 -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: 63095938a88e1994b174a29d9c1bcca25fa84562
|
4
|
+
data.tar.gz: 4df7ece6ed84e45245081a7b6617372cd386385e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: abd18392e43a5413199e6b7ab482afdb4c5782c5eeb65c298d916279df060df614b7875e3ad836a803064d5aa0c04c093eb682753397ddb6b65bfa26550be9d6
|
7
|
+
data.tar.gz: 0f03c20ff5e6d240d57586a133cc531a6a68ac2fcf4f4aea4ac931726cdf7420f92ea736fadec0f0c715e91c395ccc1ca73f3e683da42b89f5544f5afe3d02eb
|
data/CHANGELOG.md
CHANGED
data/lib/slop.rb
CHANGED
data/lib/slop/option.rb
CHANGED
@@ -3,6 +3,7 @@ module Slop
|
|
3
3
|
DEFAULT_CONFIG = {
|
4
4
|
help: true,
|
5
5
|
tail: false,
|
6
|
+
underscore_flags: true,
|
6
7
|
}
|
7
8
|
|
8
9
|
# An Array of flags this option matches.
|
@@ -107,7 +108,14 @@ module Slop
|
|
107
108
|
|
108
109
|
# Returns the last key as a symbol. Used in Options.to_hash.
|
109
110
|
def key
|
110
|
-
|
111
|
+
key = config[:key] || flags.last.sub(/\A--?/, '')
|
112
|
+
key = key.tr '-', '_' if underscore_flags?
|
113
|
+
key.to_sym
|
114
|
+
end
|
115
|
+
|
116
|
+
# Returns true if this option should be displayed with dashes transformed into underscores.
|
117
|
+
def underscore_flags?
|
118
|
+
config[:underscore_flags]
|
111
119
|
end
|
112
120
|
|
113
121
|
# Returns true if this option should be displayed in help text.
|
data/lib/slop/options.rb
CHANGED
@@ -3,9 +3,10 @@ module Slop
|
|
3
3
|
include Enumerable
|
4
4
|
|
5
5
|
DEFAULT_CONFIG = {
|
6
|
-
suppress_errors:
|
7
|
-
type:
|
8
|
-
banner:
|
6
|
+
suppress_errors: false,
|
7
|
+
type: "null",
|
8
|
+
banner: true,
|
9
|
+
underscore_flags: true,
|
9
10
|
}
|
10
11
|
|
11
12
|
# The Array of Option instances we've created.
|
data/lib/slop/result.rb
CHANGED
@@ -33,7 +33,11 @@ module Slop
|
|
33
33
|
|
34
34
|
# Returns an Option if it exists. Ignores any prefixed hyphens.
|
35
35
|
def option(flag)
|
36
|
-
cleaned = -> (f)
|
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
|
37
41
|
options.find do |o|
|
38
42
|
o.flags.any? { |f| cleaned.(f) == cleaned.(flag) }
|
39
43
|
end
|
data/test/option_test.rb
CHANGED
@@ -21,6 +21,10 @@ describe Slop::Option do
|
|
21
21
|
assert_equal :foo_bar, option(%w(-f --foo-bar), nil).key
|
22
22
|
end
|
23
23
|
|
24
|
+
it "when specified, it won't convert dashes to underscores to make multi-word options symbol-friendly" do
|
25
|
+
assert_equal :'foo-bar', option(%w(-f --foo-bar), nil, underscore_flags: false).key
|
26
|
+
end
|
27
|
+
|
24
28
|
it "can be overridden" do
|
25
29
|
assert_equal :bar, option(%w(-f --foo), nil, key: "bar").key
|
26
30
|
end
|
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.5.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: 2017-05-
|
11
|
+
date: 2017-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|