xoptparse 0.3.0 → 0.4.0
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/Gemfile.lock +1 -1
- data/lib/xoptparse.rb +30 -8
- data/lib/xoptparse/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7394cd54a72531488fcb897fba20e2fbac39d299bed1ff2f06e38c04536050da
|
4
|
+
data.tar.gz: 15c8862b6f254cb26edf6e7d9aabc5b3b09603c421037e309437dc91f80ba418
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef48822f56f652134a67e0f86c97a40c9750286f5de3ddbcdf8f2b3f13e7351c5c07964f7538303c86811e350843935a0eb9b66c0afca926d90b5aaadd2171ad
|
7
|
+
data.tar.gz: 1b3b45a58ebea67193baab6351aa2403060820e0102d0126c4767c96a8ecac7eb53d407755da8c53be4a8d19d0ba802d106c3954dea945e0122fbfccfb20837d
|
data/Gemfile.lock
CHANGED
data/lib/xoptparse.rb
CHANGED
@@ -55,18 +55,24 @@ class XOptionParser < ::OptionParser
|
|
55
55
|
end
|
56
56
|
private :search_arg_switch_atype
|
57
57
|
|
58
|
-
def fix_arg_switch(sw0)
|
59
|
-
|
60
|
-
|
58
|
+
def fix_arg_switch(sw0) # rubocop:disable Metrics/AbcSize
|
59
|
+
if !(sw0.short || sw0.long)
|
60
|
+
pattern, conv = search_arg_switch_atype(sw0)
|
61
|
+
Switch::SimpleArgument.new(pattern, conv, nil, nil, sw0.desc[0], sw0.desc[1..], sw0.block)
|
62
|
+
elsif sw0.is_a?(Switch::PlacedArgument) && sw0.long.size == 1 && /^--\[no-\]/ =~ sw0.long.first
|
63
|
+
args = [sw0.pattern, sw0.conv, sw0.short, sw0.long, sw0.arg, sw0.desc, sw0.block]
|
64
|
+
Switch::FlagArgument.new(*args)
|
65
|
+
else
|
66
|
+
sw0
|
67
|
+
end
|
61
68
|
end
|
62
69
|
private :fix_arg_switch
|
63
70
|
|
64
71
|
def make_switch(opts, block = nil)
|
65
72
|
sw = super(opts, block || proc {})
|
66
|
-
sw0 = sw[0]
|
73
|
+
sw0 = sw[0] = fix_arg_switch(sw[0])
|
67
74
|
return sw if sw0.short || sw0.long
|
68
75
|
|
69
|
-
sw0 = fix_arg_switch(sw0)
|
70
76
|
long = sw0.arg_parameters.map(&:first)
|
71
77
|
[sw0, nil, long]
|
72
78
|
end
|
@@ -85,24 +91,30 @@ class XOptionParser < ::OptionParser
|
|
85
91
|
|
86
92
|
arg_sws.each do |sw|
|
87
93
|
conv = proc { |v| sw.send(:conv_arg, *sw.send(:parse_arg, v))[2] }
|
94
|
+
callable = false
|
88
95
|
a = sw.ranges.map do |r|
|
89
96
|
if r.end.nil?
|
90
97
|
rest_size = r.begin + opt_count
|
91
98
|
req_count -= r.begin
|
92
99
|
opt_count = 0
|
100
|
+
callable = true if rest_size.positive?
|
93
101
|
argv.slice!(0...rest_size).map(&conv)
|
94
102
|
elsif r.begin.zero?
|
95
|
-
next
|
103
|
+
next nil if opt_count.zero?
|
96
104
|
|
97
105
|
opt_count -= 1
|
106
|
+
callable = true
|
98
107
|
conv.call(argv.shift)
|
99
108
|
else
|
100
109
|
req_count -= 1
|
110
|
+
callable = true
|
101
111
|
conv.call(argv.shift)
|
102
112
|
end
|
103
113
|
end
|
104
|
-
|
105
|
-
|
114
|
+
if callable
|
115
|
+
val = sw.block.call(*a)
|
116
|
+
setter&.call(sw.switch_name, val)
|
117
|
+
end
|
106
118
|
end
|
107
119
|
|
108
120
|
argv
|
@@ -223,5 +235,15 @@ class XOptionParser < ::OptionParser
|
|
223
235
|
end
|
224
236
|
end
|
225
237
|
end
|
238
|
+
|
239
|
+
class FlagArgument < PlacedArgument
|
240
|
+
def parse(arg, argv, &error)
|
241
|
+
if !arg && (argv.empty? || /\A-/ =~ argv[0])
|
242
|
+
conv_arg(arg)
|
243
|
+
else
|
244
|
+
super(arg, argv, &error)
|
245
|
+
end
|
246
|
+
end
|
247
|
+
end
|
226
248
|
end
|
227
249
|
end
|
data/lib/xoptparse/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xoptparse
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ofk
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-07-
|
11
|
+
date: 2020-07-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|