options_by_example 1.1.0 → 1.2.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: 2d803c63947acbb818c4fbf749cdb18084e6b0750678f9e600369ce543b78536
4
- data.tar.gz: 21d6c8a4866627102f82d12a2805eb60850e6a24eb04d0ec064ea5af55dd87a2
3
+ metadata.gz: b9973ed4bcfac2c5bdd856347b1956fe52fc134c0c120e288548d164179e3578
4
+ data.tar.gz: a9f55ef81262189094c8718713a55a93c05b5d64d5655ef6fd1ce5db1ddddb29
5
5
  SHA512:
6
- metadata.gz: a6e16dbd993f098415710aacd89e859ff9ac9403256a648a51fd4ab7754d91aa473e8c5b53f055ab0378d4acf1977e6b30f8826d1a626f6bcdeef4e0eb15e233
7
- data.tar.gz: b9dcfa2249f316554b416f788109486caecefdc68c8d48890cc3e0033a3270509bea96fbe994931413bae7160c035e8968f63f855e59f522d67149d20e7fc15b
6
+ metadata.gz: 1670b512ab6a4517bc38141a403d88798f5ca250b23dd7c7d3958a542dc9c1aeeca42b1d7ecfc76219c553d14c3a96e4662806712e1abc410b0f5a675254d3e2
7
+ data.tar.gz: b82aaa8cca78d5c92166c64268fc49edb20507b504bd87bec50446d1de9877b497169a4f657457e9fc6469fe6a38a7baabe488aeccf95c6a6ca10a584eafe843
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class OptionsByExample
4
- VERSION = '1.1.0'
4
+ VERSION = '1.2.0'
5
5
  end
6
6
 
7
7
 
@@ -11,10 +11,15 @@ __END__
11
11
  # Minor version bump when backward-compatible changes or enhancements
12
12
  # Patch version bump when backward-compatible bug fixes, security updates etc
13
13
 
14
- 1.0.1
14
+ 1.2.0
15
15
 
16
- - Update readme file with features and an example
16
+ - Ensure compatibility with Ruby versions 1.9.3 and newer
17
+
18
+ 1.1.0
19
+
20
+ - Renamed the gem from usage_by_example to options_by_example
17
21
  - Update the gemspec to include readme and ruby files only
22
+ - Update readme file with features and an example
18
23
 
19
24
  1.0.0
20
25
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "options_by_example/version"
3
+ require 'options_by_example/version'
4
4
 
5
5
 
6
6
  class OptionsByExample
@@ -46,7 +46,7 @@ class OptionsByExample
46
46
  @option_names = {}
47
47
  text.scan(/((--?\w+)(, --?\w+)*) ?(\w+)?/) do
48
48
  opts = $1.split(", ")
49
- opts.each { |each| @option_names[each] = [opts.last.tr('-', ''), $4&.downcase] }
49
+ opts.each { |each| @option_names[each] = [opts.last.tr('-', ''), ($4.downcase if $4)] }
50
50
  end
51
51
 
52
52
  # ---- 3) Include help option by default --------------------------
@@ -54,7 +54,7 @@ class OptionsByExample
54
54
  @option_names.update("-h" => :help, "--help" => :help)
55
55
  end
56
56
 
57
- def parse(argv, exit_on_error: true)
57
+ def parse(argv, options = nil)
58
58
  array = argv.dup
59
59
  @arguments = {}
60
60
  @options = {}
@@ -106,12 +106,15 @@ class OptionsByExample
106
106
  if not array.empty?
107
107
  # Custom error message if most recent option did not require argument
108
108
  raise "Got unexpected argument for option #{most_recent_option}" if most_recent_option
109
+ min_length = @argument_names_required.size
110
+ max_length = @argument_names_optional.size + min_length
109
111
  raise "Expected #{min_length}#{"-#{max_length}" if max_length > min_length} arguments, got more"
110
112
  end
111
113
 
112
114
  return self
113
115
 
114
116
  rescue RuntimeError => err
117
+ exit_on_error = options ? options[:exit_on_error] : true
115
118
  if exit_on_error
116
119
  puts "ERROR: #{err.message}\n\n" unless err.message.empty?
117
120
  puts @usage
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: options_by_example
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adrian Kuhn
@@ -34,7 +34,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
34
34
  requirements:
35
35
  - - ">="
36
36
  - !ruby/object:Gem::Version
37
- version: 2.6.0
37
+ version: 1.9.3
38
38
  required_rubygems_version: !ruby/object:Gem::Requirement
39
39
  requirements:
40
40
  - - ">="