slop 4.7.0 → 4.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +7 -4
- data/CHANGELOG.md +21 -0
- data/lib/slop/options.rb +4 -4
- data/lib/slop/parser.rb +0 -1
- data/lib/slop/types.rb +4 -3
- data/lib/slop.rb +2 -2
- data/test/option_test.rb +2 -2
- data/test/options_test.rb +2 -2
- data/test/slop_test.rb +10 -0
- data/test/types_test.rb +32 -2
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ec00c622e6cf0e93fdcebfa0964225fd2a2be127fcf21191a47bb96a64afb2b
|
4
|
+
data.tar.gz: 129ca3a92e02e2ac696c4a1dbc805a6316e59f8802d7c06fe3b071ef4467e6e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b6280d06c83bafc75d2b2169d0c08ac1470031777aad641a162dda1657dbaa8940dad56ae20431fe7dc34eba52ab6a6f42a8dbb0207ad0f568cc21d5ed84884d
|
7
|
+
data.tar.gz: ce64d1d1d442cbb4a09c130e14a7f4d9837d53cf6ed2b4b4c3db1264650ebaba50cf500418737bbf265940dc2f430c14b30641394aca1b5626680fec4d4f4411
|
data/.travis.yml
CHANGED
@@ -13,12 +13,15 @@ rvm:
|
|
13
13
|
- 2.1
|
14
14
|
- 2.2
|
15
15
|
- 2.3.4
|
16
|
-
- 2.4.
|
17
|
-
- 2.5.
|
18
|
-
- 2.6.
|
19
|
-
-
|
16
|
+
- 2.4.9
|
17
|
+
- 2.5.7
|
18
|
+
- 2.6.5
|
19
|
+
- 2.7.0
|
20
|
+
- jruby-9.2.9.0
|
20
21
|
- jruby-head
|
21
22
|
- ruby-head
|
23
|
+
jdk:
|
24
|
+
- openjdk8
|
22
25
|
notifications:
|
23
26
|
email:
|
24
27
|
on_success: change
|
data/CHANGELOG.md
CHANGED
@@ -1,12 +1,33 @@
|
|
1
1
|
Changelog
|
2
2
|
=========
|
3
3
|
|
4
|
+
v4.8.1 (2020-03-31)
|
5
|
+
-------------------
|
6
|
+
|
7
|
+
Bug fixes:
|
8
|
+
* Fix keyword argument warning. [#251](https://github.com/leejarvis/slop/pull/251)
|
9
|
+
|
10
|
+
|
11
|
+
v4.8.0 (2020-01-17)
|
12
|
+
-------------------
|
13
|
+
|
14
|
+
Features:
|
15
|
+
* Add support for prefixing integer values with `+` character
|
16
|
+
[#243](https://github.com/leejarvis/slop/pull/243) (Juha Ylitalo)
|
17
|
+
* Add support for parsing floats with scientific notation
|
18
|
+
[#250](https://github.com/leejarvis/slop/pull/250) (Hansuk Hong)
|
19
|
+
|
20
|
+
Maintenance:
|
21
|
+
* Add 2.7.0 to CI and fix warnings
|
22
|
+
[#248](https://github.com/leejarvis/slop/pull/248) (Juha Ylitalo, Andrew Kane)
|
23
|
+
|
4
24
|
v4.7.0 (2019-06-29)
|
5
25
|
-------------------
|
6
26
|
|
7
27
|
Features:
|
8
28
|
* 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
29
|
* 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))
|
30
|
+
|
10
31
|
Bug fixes
|
11
32
|
* Ensure non-string option types have their flags consumed properly [#241] (Sutou Kouhei)
|
12
33
|
|
data/lib/slop/options.rb
CHANGED
@@ -24,12 +24,12 @@ module Slop
|
|
24
24
|
# The String banner prefixed to the help string.
|
25
25
|
attr_accessor :banner
|
26
26
|
|
27
|
-
def initialize(**config)
|
27
|
+
def initialize(**config, &block)
|
28
28
|
@options = []
|
29
29
|
@separators = []
|
30
30
|
@banner = config[:banner].is_a?(String) ? config[:banner] : config.fetch(:banner, "usage: #{$0} [options]")
|
31
31
|
@config = DEFAULT_CONFIG.merge(config)
|
32
|
-
@parser = Parser.new(self,
|
32
|
+
@parser = Parser.new(self, **@config)
|
33
33
|
|
34
34
|
yield self if block_given?
|
35
35
|
end
|
@@ -52,7 +52,7 @@ module Slop
|
|
52
52
|
desc = flags.pop unless flags.last.start_with?('-')
|
53
53
|
config = self.config.merge(config)
|
54
54
|
klass = Slop.string_to_option_class(config[:type].to_s)
|
55
|
-
option = klass.new(flags, desc, config, &block)
|
55
|
+
option = klass.new(flags, desc, **config, &block)
|
56
56
|
|
57
57
|
add_option option
|
58
58
|
end
|
@@ -82,7 +82,7 @@ module Slop
|
|
82
82
|
def method_missing(name, *args, **config, &block)
|
83
83
|
if respond_to_missing?(name)
|
84
84
|
config[:type] = name
|
85
|
-
on(*args, config, &block)
|
85
|
+
on(*args, **config, &block)
|
86
86
|
else
|
87
87
|
super
|
88
88
|
end
|
data/lib/slop/parser.rb
CHANGED
data/lib/slop/types.rb
CHANGED
@@ -44,16 +44,17 @@ module Slop
|
|
44
44
|
# Cast the option argument to an Integer.
|
45
45
|
class IntegerOption < Option
|
46
46
|
def call(value)
|
47
|
-
value =~ /\A
|
47
|
+
value =~ /\A[+-]?\d+\z/ && value.to_i
|
48
48
|
end
|
49
49
|
end
|
50
50
|
IntOption = IntegerOption
|
51
51
|
|
52
52
|
# Cast the option argument to a Float.
|
53
53
|
class FloatOption < Option
|
54
|
+
FLOAT_STRING_REGEXP = /\A[+-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+-]?\d+)?\z/.freeze
|
55
|
+
|
54
56
|
def call(value)
|
55
|
-
|
56
|
-
value =~ /\A-?\d*\.*\d+\z/ && value.to_f
|
57
|
+
value =~ FLOAT_STRING_REGEXP && value.to_f
|
57
58
|
end
|
58
59
|
end
|
59
60
|
|
data/lib/slop.rb
CHANGED
@@ -6,7 +6,7 @@ require 'slop/types'
|
|
6
6
|
require 'slop/error'
|
7
7
|
|
8
8
|
module Slop
|
9
|
-
VERSION = '4.
|
9
|
+
VERSION = '4.8.1'
|
10
10
|
|
11
11
|
# Parse an array of options (defaults to ARGV). Accepts an
|
12
12
|
# optional hash of configuration options and block.
|
@@ -20,7 +20,7 @@ module Slop
|
|
20
20
|
#
|
21
21
|
# Returns a Slop::Result.
|
22
22
|
def self.parse(items = ARGV, **config, &block)
|
23
|
-
Options.new(config, &block).parse(items)
|
23
|
+
Options.new(**config, &block).parse(items)
|
24
24
|
end
|
25
25
|
|
26
26
|
# Example:
|
data/test/option_test.rb
CHANGED
data/test/options_test.rb
CHANGED
@@ -121,11 +121,11 @@ describe Slop::Options do
|
|
121
121
|
|
122
122
|
describe "custom banner" do
|
123
123
|
it "is prefixed with defined banner" do
|
124
|
-
@options_config = Slop::Options.new({banner: "custom banner"})
|
124
|
+
@options_config = Slop::Options.new(**{banner: "custom banner"})
|
125
125
|
assert_match(/^custom banner/, @options_config.to_s)
|
126
126
|
end
|
127
127
|
it "banner is disabled" do
|
128
|
-
@options_config = Slop::Options.new({banner: false})
|
128
|
+
@options_config = Slop::Options.new(**{banner: false})
|
129
129
|
assert_match("", @options_config.to_s)
|
130
130
|
end
|
131
131
|
end
|
data/test/slop_test.rb
CHANGED
@@ -1,6 +1,16 @@
|
|
1
1
|
require "test_helper"
|
2
2
|
|
3
3
|
describe Slop do
|
4
|
+
describe ".parse" do
|
5
|
+
it "parses a list of arguments" do
|
6
|
+
result = Slop.parse(%w[--name Lee]) do |o|
|
7
|
+
o.string "--name"
|
8
|
+
end
|
9
|
+
|
10
|
+
assert_equal "Lee", result[:name]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
4
14
|
describe ".option_defined?" do
|
5
15
|
it "handles bad constant names" do
|
6
16
|
assert_equal false, Slop.option_defined?("Foo?Bar")
|
data/test/types_test.rb
CHANGED
@@ -32,11 +32,15 @@ describe Slop::IntegerOption do
|
|
32
32
|
before do
|
33
33
|
@options = Slop::Options.new
|
34
34
|
@age = @options.integer "--age"
|
35
|
-
@
|
35
|
+
@minus = @options.integer "--minus"
|
36
|
+
@plus = @options.integer "--plus"
|
37
|
+
@result = @options.parse %w(--age 20 --minus -10 --plus +30)
|
36
38
|
end
|
37
39
|
|
38
40
|
it "returns the value as an integer" do
|
39
41
|
assert_equal 20, @result[:age]
|
42
|
+
assert_equal (-10), @result[:minus]
|
43
|
+
assert_equal 30, @result[:plus]
|
40
44
|
end
|
41
45
|
|
42
46
|
it "returns nil for non-numbers by default" do
|
@@ -50,11 +54,37 @@ describe Slop::FloatOption do
|
|
50
54
|
@options = Slop::Options.new
|
51
55
|
@apr = @options.float "--apr"
|
52
56
|
@apr_value = 2.9
|
53
|
-
@
|
57
|
+
@minus = @options.float "--minus"
|
58
|
+
@plus = @options.float "--plus"
|
59
|
+
@scientific_notation = @options.float "--scientific-notation"
|
60
|
+
@scientific_notation_value = 4e21
|
61
|
+
@result = @options.parse %W(--apr #{@apr_value} --minus -6.1 --plus +9.4 --scientific-notation #{@scientific_notation_value})
|
54
62
|
end
|
55
63
|
|
56
64
|
it "returns the value as a float" do
|
57
65
|
assert_equal @apr_value, @result[:apr]
|
66
|
+
assert_equal (-6.1), @result[:minus]
|
67
|
+
assert_equal 9.4, @result[:plus]
|
68
|
+
end
|
69
|
+
|
70
|
+
it "parses scientific notations" do
|
71
|
+
assert_equal @scientific_notation_value, @result[:scientific_notation]
|
72
|
+
|
73
|
+
@scientific_notation_value = 4E21
|
74
|
+
@result = @options.parse %W(--scientific-notation #{@scientific_notation_value})
|
75
|
+
assert_equal @scientific_notation_value, @result[:scientific_notation]
|
76
|
+
|
77
|
+
@scientific_notation_value = 4.0e21
|
78
|
+
@result = @options.parse %W(--scientific-notation #{@scientific_notation_value})
|
79
|
+
assert_equal @scientific_notation_value, @result[:scientific_notation]
|
80
|
+
|
81
|
+
@scientific_notation_value = -4e21
|
82
|
+
@result = @options.parse %W(--scientific-notation #{@scientific_notation_value})
|
83
|
+
assert_equal @scientific_notation_value, @result[:scientific_notation]
|
84
|
+
|
85
|
+
@scientific_notation_value = 4e-21
|
86
|
+
@result = @options.parse %W(--scientific-notation #{@scientific_notation_value})
|
87
|
+
assert_equal @scientific_notation_value, @result[:scientific_notation]
|
58
88
|
end
|
59
89
|
|
60
90
|
it "returns nil for non-numbers by default" 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.
|
4
|
+
version: 4.8.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:
|
11
|
+
date: 2020-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -86,8 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
86
|
- !ruby/object:Gem::Version
|
87
87
|
version: '0'
|
88
88
|
requirements: []
|
89
|
-
|
90
|
-
rubygems_version: 2.7.6
|
89
|
+
rubygems_version: 3.0.3
|
91
90
|
signing_key:
|
92
91
|
specification_version: 4
|
93
92
|
summary: Simple Lightweight Option Parsing
|