slop 4.7.0 → 4.8.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 125a7e982b88caf3675166359579515c0af86540002d463042c336c45de8f310
4
- data.tar.gz: a0518f68ab2a02cb7cdcdc18fbf0fb9134eac55dc903b1486fa569e66b15a18a
3
+ metadata.gz: 3519c62b207c9004fe10decdefafc6f429540355aaf42d6d001b726524546935
4
+ data.tar.gz: f23973419fa0e1bbed6f7e3f1925ccfee2b28e3c87db57aa19f76b5df5c984c5
5
5
  SHA512:
6
- metadata.gz: 463bd12f9ab37a1f27ebca2bdb98954d69f3160bb64d6b8d813a319f66bde91f07c9002ebfd5267277fbbe87bfb20dc50faa0b74e7478ffe3e1acad049dd765e
7
- data.tar.gz: 0c5fa72e533dbdf3ff4bfc1f1f5c7c0944aa4e8f1afc41b41ffe7b8c29807be11b111d5f2c218a3f68034dc65243ea527cad4f0a27af56a5fefddce6e20550ba
6
+ metadata.gz: 5658a5eee5fbd320aa88de052f6d0c6345be8f73d7d40ac22b4fdebfd157b72ae3ce02c279848acb62a6ca7819318800cc3c68abe3e40499f886368d6a7798c7
7
+ data.tar.gz: 9d61f5fa3f804092ea4b56103ba509dc6392701f3260190f32d4d3e807fbb75c622c23c7b30b1b71adecedef15d3da82d7ab20bd648c4642ebe637f9dd4b41d1
@@ -13,12 +13,15 @@ rvm:
13
13
  - 2.1
14
14
  - 2.2
15
15
  - 2.3.4
16
- - 2.4.1
17
- - 2.5.3
18
- - 2.6.0
19
- - jruby-9.2.5.0
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
@@ -1,12 +1,26 @@
1
1
  Changelog
2
2
  =========
3
3
 
4
+ v4.8.0 (2020-01-17)
5
+ -------------------
6
+
7
+ Features:
8
+ * Add support for prefixing integer values with `+` character
9
+ [#243](https://github.com/leejarvis/slop/pull/243) (Juha Ylitalo)
10
+ * Add support for parsing floats with scientific notation
11
+ [#250](https://github.com/leejarvis/slop/pull/250) (Hansuk Hong)
12
+
13
+ Maintenance:
14
+ * Add 2.7.0 to CI and fix warnings
15
+ [#248](https://github.com/leejarvis/slop/pull/248) (Juha Ylitalo, Andrew Kane)
16
+
4
17
  v4.7.0 (2019-06-29)
5
18
  -------------------
6
19
 
7
20
  Features:
8
21
  * 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
22
  * 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))
23
+
10
24
  Bug fixes
11
25
  * Ensure non-string option types have their flags consumed properly [#241] (Sutou Kouhei)
12
26
 
@@ -6,7 +6,7 @@ require 'slop/types'
6
6
  require 'slop/error'
7
7
 
8
8
  module Slop
9
- VERSION = '4.7.0'
9
+ VERSION = '4.8.0'
10
10
 
11
11
  # Parse an array of options (defaults to ARGV). Accepts an
12
12
  # optional hash of configuration options and block.
@@ -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, @config)
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
@@ -52,7 +52,6 @@ module Slop
52
52
 
53
53
  # support `foo=bar`
54
54
  orig_flag = flag.dup
55
- orig_arg = arg
56
55
  if match = flag.match(/([^=]+)=([^=]+)/)
57
56
  flag, arg = match.captures
58
57
  end
@@ -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-?\d+\z/ && value.to_i
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
- # TODO: scientific notation, etc.
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
 
@@ -1,8 +1,8 @@
1
1
  require 'test_helper'
2
2
 
3
3
  describe Slop::Option do
4
- def option(*args)
5
- Slop::Option.new(*args)
4
+ def option(*args, **kwargs, &block)
5
+ Slop::Option.new(*args, **kwargs, &block)
6
6
  end
7
7
 
8
8
  describe "#flag" do
@@ -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
@@ -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
- @result = @options.parse %w(--age 20)
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
- @result = @options.parse %W(--apr #{@apr_value})
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.7.0
4
+ version: 4.8.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: 2019-06-29 00:00:00.000000000 Z
11
+ date: 2020-01-17 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
- rubyforge_project:
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