optparse2 0.7.5 → 0.7.6

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: 5b075c92a3cfbcdaf6d194a8c10b5a6bc1adb503cce26dc9e54d1ce98e01e234
4
- data.tar.gz: aa78b0efbaaff344675ee564c43db64b0da6118505b9bd66820925e146b8a40a
3
+ metadata.gz: '089aa30260171fcc53efa5d5099338973990015878df07b4a3c9ae023ae7d0c6'
4
+ data.tar.gz: 2e46af429af2a2c3576bb5bfd2f32bc4bcb448fb2ecb73c34f419de705d502d6
5
5
  SHA512:
6
- metadata.gz: 7b22ee332ef698a1f87daba95815adc0bb7a174e7d2985cd69f6e21fa0d038e85926a7d6a103202e2d7f26519acecdb554f75f1ba621a89e235384d0f12c8bfd
7
- data.tar.gz: 396f15d23ddd21d3a5a76b243d99fc8cd591244b3c20b1610589af661e4d8ba30c3e7aab804c6b6fdd50138f70abccd372e938be7c4c17c7377f16cb875f2e27
6
+ metadata.gz: c2f53a2bc1382025cdc0c66ddbfe2878bbcec9a21ddb66b5c54e6952fdef9a32d4b9d9c11ea68875ec2b1e875f135cd33c48ec54d138cc450c7d92428e9a8ed0
7
+ data.tar.gz: 66b6650a5aa9b38020ccb8a053268037188897b7b6d2514b14b384fb488b1d7553f005bd9ed266b4ae293ad506cc45ad6f8fe6384125bbc9928e1b9b79b1d42b
@@ -150,7 +150,7 @@ class OptParse2
150
150
  # Default values of switches are used when the switch is never passed in.
151
151
  # If the `value` that's provided doesn't respond to `.call`, it's converted to a proc.
152
152
  # If `bypass` is truthy, then the default value is never passed to the block's proc (if any)
153
- def set_default(value, description, bypass)
153
+ def set_default(value, description, bypass, no_default_description)
154
154
  if required?
155
155
  raise ArgumentError, 'cannot supply a default value for a required argument'
156
156
  end
@@ -165,6 +165,7 @@ class OptParse2
165
165
  @default_proc = proc { |_switch_name| value }
166
166
  end
167
167
 
168
+ @no_default_description = no_default_description
168
169
  @default_description = description
169
170
  @default_bypass = bypass
170
171
  end
@@ -174,9 +175,10 @@ class OptParse2
174
175
  def default? = defined?(@default_proc)
175
176
  def default = @default_proc&.call(switch_name)
176
177
 
177
- def default_description = @default_description || default.inspect
178
+ def default_description = @default_description || default.to_s
178
179
  def desc
179
180
  return super unless defined? @default_proc
181
+ return super if @no_default_description
180
182
  x = super
181
183
  x << '' if x.empty?
182
184
  x[-1] += " [default: #{default_description}]"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class OptParse2
4
- VERSION = "0.7.5"
4
+ VERSION = "0.7.6"
5
5
  end
data/lib/optparse2.rb CHANGED
@@ -35,7 +35,7 @@ class OptParse2
35
35
  key: @group,
36
36
  default: nodefault=true,
37
37
  default_bypass: false,
38
- default_description: nil,
38
+ default_description: no_default_description=true,
39
39
  required: false,
40
40
  multiple: nil
41
41
  )
@@ -56,12 +56,12 @@ class OptParse2
56
56
 
57
57
  sw.set_required true if required
58
58
 
59
- if nodefault && default_description != nil
59
+ if nodefault && !no_default_description
60
60
  raise ArgumentError, "default: not supplied, but default_description: given"
61
61
  elsif nodefault && default_bypass
62
62
  raise ArgumentError, "default: not supplied, but default_bypass: given"
63
63
  elsif not nodefault
64
- sw.set_default(default, default_description, default_bypass)
64
+ sw.set_default(default, default_description, default_bypass, !no_default_description)
65
65
  @defaults << sw
66
66
  end
67
67
 
@@ -270,6 +270,12 @@ class OptParse2
270
270
  end
271
271
  end
272
272
 
273
+ __END__
274
+ OptParse2.new do |op|
275
+ op.on '-f', '--foo=BAR', 'does it', default: 10, default_description: nil
276
+ puts op.help
277
+ end
278
+
273
279
  __END__
274
280
  OptParse2.new do |op|
275
281
  op.on '--foo=FOO', multiple: :first! do puts "FOO: #{it}"; it end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: optparse2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.5
4
+ version: 0.7.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - SamW