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 +4 -4
- data/lib/optparse2/switch-helpers.rb +4 -2
- data/lib/optparse2/version.rb +1 -1
- data/lib/optparse2.rb +12 -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
|
|
|
@@ -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
|