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 +4 -4
- data/lib/optparse2/switch-helpers.rb +4 -2
- data/lib/optparse2/version.rb +1 -1
- data/lib/optparse2.rb +9 -3
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: '089aa30260171fcc53efa5d5099338973990015878df07b4a3c9ae023ae7d0c6'
|
|
4
|
+
data.tar.gz: 2e46af429af2a2c3576bb5bfd2f32bc4bcb448fb2ecb73c34f419de705d502d6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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.
|
|
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}]"
|
data/lib/optparse2/version.rb
CHANGED
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:
|
|
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 &&
|
|
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
|