options_by_example 3.3.0 → 3.4.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: 8ced46483d8abae62122bb45cd0d4753408c4d93e08405a3409583ec9fcfb477
4
- data.tar.gz: e8484baa8976c72154fb2da2509482d985501c08960e7e67fdf04731e307787b
3
+ metadata.gz: beeaa2ae22a04cfe49102108f616bad5d3fb63b00156bb34647774ba07c8def0
4
+ data.tar.gz: e2af434e1812a6244c276bea7b00b52b97411927ccc207e843f4866e64356d08
5
5
  SHA512:
6
- metadata.gz: 22f691bf1fc36e14868996b32b15de17a1760add666aa046e6dc57fb0e09f8dad75c7c18260255930c88ea3e56a1c994285dd320a659e6c9ee92fc4ae45d3f10
7
- data.tar.gz: 1d54dca36e9829f2018af7493586e18ca7d590819d112e28482c93684212adc4ccd53e5c5183d49885c927f4ddb9e23c0654874ddbceb0e617f95c6fc6b96258
6
+ metadata.gz: fca827e7190634ca8382ff90d074a276fd4367a609fad77b3d58a8488f85b97e3e8493fe2a717fd9a9aff3fefdde4315058c1512addaf4b1d7663f1a2dc201db
7
+ data.tar.gz: a2ce56d793153540e2c9c4959dc7af5aff0e73a4c32037a738a368f06128d4f35730411f8cce8875e5e1a3c153e6e4a4344de006171ca1b70d1b24737eeaf819
@@ -41,6 +41,7 @@ class OptionsByExample
41
41
  expand_dash_number_to_dash_n_option
42
42
  raise_if_unknown_options
43
43
  parse_options
44
+ coerce_num_date_time_etc
44
45
 
45
46
  validate_number_of_arguments
46
47
  parse_required_arguments
@@ -114,25 +115,7 @@ class OptionsByExample
114
115
 
115
116
  if argument_name
116
117
  raise "Expected argument for option '#{option}', got none" if args.empty?
117
- value = args.shift
118
-
119
- begin
120
- case argument_name
121
- when 'NUM'
122
- expected_type = 'an integer value'
123
- value = Integer value
124
- when 'DATE'
125
- expected_type = 'a date (e.g. YYYY-MM-DD)'
126
- value = Date.parse value
127
- when 'TIME'
128
- expected_type = 'a timestamp (e.g. HH:MM:SS)'
129
- value = Time.parse value
130
- end
131
- rescue ArgumentError
132
- raise "Invalid argument \"#{value}\" for option '#{option}', please provide #{expected_type}"
133
- end
134
-
135
- @argument_values[option_name] = value
118
+ @argument_values[option_name] = args.shift
136
119
  @option_took_argument = option
137
120
  else
138
121
  @option_took_argument = nil
@@ -142,6 +125,27 @@ class OptionsByExample
142
125
  end
143
126
  end
144
127
 
128
+ def coerce_num_date_time_etc
129
+ @option_names.each do |option, (each, argument_name)|
130
+ next unless value = @argument_values[each]
131
+ begin
132
+ case argument_name
133
+ when 'NUM'
134
+ expected_type = 'an integer value'
135
+ @argument_values[each] = Integer value
136
+ when 'DATE'
137
+ expected_type = 'a date (e.g. YYYY-MM-DD)'
138
+ @argument_values[each] = Date.parse value
139
+ when 'TIME'
140
+ expected_type = 'a timestamp (e.g. HH:MM:SS)'
141
+ @argument_values[each] = Time.parse value
142
+ end
143
+ rescue ArgumentError
144
+ raise "Invalid argument \"#{value}\" for option '#{option}', please provide #{expected_type}"
145
+ end
146
+ end
147
+ end
148
+
145
149
  def validate_number_of_arguments
146
150
  count_optional_arguments = @argument_names.values.count(:optional)
147
151
  count_required_arguments = @argument_names.values.count(:required)
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class OptionsByExample
4
- VERSION = '3.3.0'
4
+ VERSION = '3.4.0'
5
5
  end
6
6
 
7
7
 
@@ -11,6 +11,12 @@ __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
+ 3.4.0
15
+ - Ensure default values are coerced too
16
+ - Print error message to stdout
17
+ - New method #expect_at_most_one_except (experimental)
18
+ - New method #expect_at_most_one_of (experimental)
19
+
14
20
  3.3.0
15
21
  - Expand dash-number to dash-n option
16
22
  - Complete support for inline specification of options
@@ -28,8 +28,18 @@ class OptionsByExample
28
28
  puts @usage_spec.message
29
29
  exit 0
30
30
  rescue RuntimeError => err
31
- puts "ERROR: #{err.message}"
32
- exit 1
31
+ abort "ERR: #{err.message}"
32
+ end
33
+
34
+ def expect_at_most_one_except(*extra_options)
35
+ expect_at_most_one_of *(@options.keys - extra_options)
36
+ end
37
+
38
+ def expect_at_most_one_of(*mutually_exclusive_options)
39
+ provided_options = @options.keys & mutually_exclusive_options
40
+ if provided_options.length > 1
41
+ abort "ERR: Found more than one mutually-exclusive option {#{provided_options.join ', '}}"
42
+ end
33
43
  end
34
44
 
35
45
  def fetch(*args, &block)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: options_by_example
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.0
4
+ version: 3.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adrian Kuhn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-02-01 00:00:00.000000000 Z
11
+ date: 2026-02-03 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: