optparse2 0.7.4 → 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: 1fb6261613557a808dfda4002a86d4218d955804583135a3489ce5de01ba0e0e
4
- data.tar.gz: babfce64dd51938c50999db68237a920a9270701c85b415e5fde510796134189
3
+ metadata.gz: '089aa30260171fcc53efa5d5099338973990015878df07b4a3c9ae023ae7d0c6'
4
+ data.tar.gz: 2e46af429af2a2c3576bb5bfd2f32bc4bcb448fb2ecb73c34f419de705d502d6
5
5
  SHA512:
6
- metadata.gz: b7b7521fc75776437521cbf73fc024fc15ffa2f1a5b59ed7c43319f4fa8b103083e7e8eced9ae63d74475d741d49f84b43f4413cd806ceb41199223bd545ee0e
7
- data.tar.gz: ef7eb6f76bd62d96d293303aed61d3ee884212145c6507cb373877b6fa19005c6bc5e6be6ce2c328ed963c11fee6b931c4dbbcdb68fbb2ef29d9fa04ff33d631
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.4"
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
 
@@ -131,12 +131,15 @@ class OptParse2
131
131
  visit :each_option do |sw|
132
132
  next if !sw.default? || context.key?(key = sw.switch_name.to_sym)
133
133
 
134
+ =begin TODO: figure out how to re-parse variables (so it goes thru the whole validation scheme for defaults?)
134
135
  if sw.default_bypass?
135
136
  context[key] = sw.default
136
137
  else
137
138
  flag = sw.short.first || sw.long.first || raise("<INTERNAL ERROR: CAN THIS EVER HAPPEN?>")
138
139
  _super_order! [flag, sw.default], into: context
139
140
  end
141
+ =end
142
+ context[key] = sw.default
140
143
  end
141
144
  end
142
145
 
@@ -267,6 +270,12 @@ class OptParse2
267
270
  end
268
271
  end
269
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
+
270
279
  __END__
271
280
  OptParse2.new do |op|
272
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.4
4
+ version: 0.7.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - SamW