optparse2 0.5.0 → 0.5.2
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/version.rb +1 -1
- data/lib/optparse2.rb +10 -33
- 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: d3dff76909d0005ee325d16f79bfa00b18d26a65b3b06b018eef33713e40d250
|
|
4
|
+
data.tar.gz: 14733f7d9258908dc1df030b475937590089d1f6eb45f0a99f7df8dbcc6a0ded
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e715049dd9d3d3089c6d7ae994666b497eab0436927fe9a98114fcf1d46456798284fb5402fde4edf34ff2dcaf95f5856067fcbcc313fe20ccc46cc0e78635d1
|
|
7
|
+
data.tar.gz: 32fc2f6d56246b215845adf065103a60be82d5daf78f3d09d6ae64c1a100664a7521cfdfbc2c362047df74933567f59fe97caa839fce054e2baec97d943e863d
|
data/lib/optparse2/version.rb
CHANGED
data/lib/optparse2.rb
CHANGED
|
@@ -6,7 +6,6 @@ OptionParser2 = OptParse2 # Alias
|
|
|
6
6
|
|
|
7
7
|
require_relative "optparse2/version"
|
|
8
8
|
require_relative "optparse2/fixes"
|
|
9
|
-
# require_relative "optparse2/helpers"
|
|
10
9
|
|
|
11
10
|
class OptParse2
|
|
12
11
|
class << self
|
|
@@ -29,20 +28,18 @@ class OptParse2
|
|
|
29
28
|
def self.summarize(*) end
|
|
30
29
|
end
|
|
31
30
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
@switch_name = val
|
|
35
|
-
end
|
|
31
|
+
attr_writer :switch_name
|
|
32
|
+
def switch_name; defined?(@switch_name) ? @switch_name : super end
|
|
36
33
|
|
|
37
|
-
def
|
|
34
|
+
def set_switch_name_possibly_block_value
|
|
38
35
|
if @block.nil? && @arg.nil?
|
|
39
|
-
q =
|
|
36
|
+
q = switch_name.to_sym
|
|
40
37
|
@block = proc { q }
|
|
41
38
|
end
|
|
39
|
+
|
|
40
|
+
self.switch_name = val
|
|
42
41
|
end
|
|
43
42
|
|
|
44
|
-
# attr_writer :switch_name
|
|
45
|
-
def switch_name; defined?(@switch_name) ? @switch_name : super end
|
|
46
43
|
|
|
47
44
|
# requires `switch_name`, `desc` to work
|
|
48
45
|
def set_default(value, description)
|
|
@@ -73,8 +70,7 @@ class OptParse2
|
|
|
73
70
|
|
|
74
71
|
sw.extend Helpers
|
|
75
72
|
if key
|
|
76
|
-
sw.
|
|
77
|
-
sw.set_block_name_because_of_switch_name
|
|
73
|
+
sw.set_switch_name_possibly_block_value key
|
|
78
74
|
end
|
|
79
75
|
sw.set_hidden if hidden
|
|
80
76
|
|
|
@@ -121,7 +117,7 @@ class OptParse2
|
|
|
121
117
|
|
|
122
118
|
result = super(argv, into: already_done, **keywords, &non_options.method(:<<))
|
|
123
119
|
|
|
124
|
-
argv2 = non_options.each_with_index.flat_map { ["--*-positional-#{_2}", _1] }
|
|
120
|
+
argv2 = (non_options + result).each_with_index.flat_map { ["--*-positional-#{_2}", _1] }
|
|
125
121
|
|
|
126
122
|
old_raise, self.raise_unknown = self.raise_unknown, false
|
|
127
123
|
begin
|
|
@@ -141,7 +137,8 @@ class OptParse2
|
|
|
141
137
|
end
|
|
142
138
|
|
|
143
139
|
argv2 = @rest[:block] ? @rest[:block].call(argv2) : argv2
|
|
144
|
-
into[@rest[:key]] = argv2 if @rest[:key]
|
|
140
|
+
into[@rest[:key]] = argv2.dup if @rest[:key]
|
|
141
|
+
argv2.clear
|
|
145
142
|
elsif !argv2.empty? && self.raise_unknown && !@positional.empty?
|
|
146
143
|
raise ParseError, "got unexpected positional argument: #{argv2.first}", caller(1)
|
|
147
144
|
else
|
|
@@ -238,23 +235,3 @@ class OptParse2
|
|
|
238
235
|
@rest = { name:, key:, required: required || 0, block: }
|
|
239
236
|
end
|
|
240
237
|
end
|
|
241
|
-
|
|
242
|
-
__END__
|
|
243
|
-
return unless $0 == __FILE__
|
|
244
|
-
require_relative 'optparse2/pathname'
|
|
245
|
-
|
|
246
|
-
# $* << '-tFOO' << '--no-cache' << '-x'
|
|
247
|
-
# $*.replace %w[123 lol what -t10 is up here]
|
|
248
|
-
$*.replace %w[1 -t3 b lol what is up]
|
|
249
|
-
|
|
250
|
-
OPTS={}
|
|
251
|
-
OptParse2.new do |op|
|
|
252
|
-
$op = op
|
|
253
|
-
op.on '-t', '--timeout=FOO', Array,required: true
|
|
254
|
-
op.pos 'file', Integer, 'sets the file name', 'is also pretty cool', 1..1000, required: true do it * 2 end
|
|
255
|
-
op.pos '[start[-end]]', 'things to do', key: 'line', default: 123
|
|
256
|
-
|
|
257
|
-
op.rest 'branch name', 'Message to submit', 'pretty coo', required: 1 do it.join ' ' end
|
|
258
|
-
op.parse! into: OPTS
|
|
259
|
-
p ["finish: ", OPTS, $*]
|
|
260
|
-
end
|