optparse2 0.7.7 → 0.8.1
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/fixes.rb +0 -5
- data/lib/optparse2/version.rb +1 -1
- data/lib/optparse2.rb +7 -16
- metadata +1 -2
- data/lib/optparse2/builder.rb +0 -48
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f72b9507463f134c1c50c41330ab92e73c087764f0e378b84bff1819f52997e6
|
|
4
|
+
data.tar.gz: 0d46f1626d79f5a056a754467338dbb640e425d46b81c36747aab525ec69b340
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6e647563d1b3ffc9d1f8501ae527a1de6c4069bc69cd7c81f0a456a2938f203ed22606383115a0dcf2d3ef2c71f680fa72810379cb14655608895ed10c915d04
|
|
7
|
+
data.tar.gz: 37805f0e018d3b842807cca56e5dcaf2906c5ad0c873171279816a658bc8b9dc6eb20faad51b4dbf4da4f557467895a4845e8104d5eb3b77f71afce748d1fea3
|
data/lib/optparse2/fixes.rb
CHANGED
|
@@ -11,9 +11,4 @@ class OptParse2
|
|
|
11
11
|
def define_head(*opts, **, &block) base.append(*(sw = make_switch(opts, block, **))); sw[0] end
|
|
12
12
|
alias def_tail_option define_tail
|
|
13
13
|
def on_tail(...) define_tail(...); self end
|
|
14
|
-
|
|
15
|
-
def initialize(*)
|
|
16
|
-
@defaults = {}
|
|
17
|
-
super
|
|
18
|
-
end
|
|
19
14
|
end
|
data/lib/optparse2/version.rb
CHANGED
data/lib/optparse2.rb
CHANGED
|
@@ -8,7 +8,6 @@ require_relative "optparse2/version"
|
|
|
8
8
|
require_relative "optparse2/fixes"
|
|
9
9
|
require_relative "optparse2/switch-helpers"
|
|
10
10
|
require_relative "optparse2/context"
|
|
11
|
-
require_relative "optparse2/builder"
|
|
12
11
|
|
|
13
12
|
class OptParse2
|
|
14
13
|
class << self
|
|
@@ -174,10 +173,13 @@ class OptParse2
|
|
|
174
173
|
ensure_all_required_arguments_were_supplied!(context)
|
|
175
174
|
|
|
176
175
|
# For each non-option argument, call the `nonopt` block
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
176
|
+
if nonopt
|
|
177
|
+
not_matched_options.each(&nonopt)
|
|
178
|
+
argv.clear
|
|
179
|
+
else
|
|
180
|
+
# Replace the original argv with the resulting options
|
|
181
|
+
argv.replace not_matched_options
|
|
182
|
+
end
|
|
181
183
|
end
|
|
182
184
|
rescue OptionParser::ParseError => err
|
|
183
185
|
abort ? abort(err) : raise
|
|
@@ -271,17 +273,6 @@ class OptParse2
|
|
|
271
273
|
end
|
|
272
274
|
end
|
|
273
275
|
|
|
274
|
-
__END__
|
|
275
|
-
|
|
276
|
-
OptParse2.new do |op|
|
|
277
|
-
op.switch('-f', '--foo=BAR', 'does it')
|
|
278
|
-
.default { p $x += 1 }
|
|
279
|
-
.build!
|
|
280
|
-
op.parse! into: opts={}
|
|
281
|
-
p opts
|
|
282
|
-
p $x
|
|
283
|
-
end
|
|
284
|
-
|
|
285
276
|
__END__
|
|
286
277
|
OptParse2.new do |op|
|
|
287
278
|
op.on '-f', '--foo=BAR', 'does it', default: 10, default_description: nil
|
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.
|
|
4
|
+
version: 0.8.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- SamW
|
|
@@ -19,7 +19,6 @@ files:
|
|
|
19
19
|
- README.md
|
|
20
20
|
- Rakefile
|
|
21
21
|
- lib/optparse2.rb
|
|
22
|
-
- lib/optparse2/builder.rb
|
|
23
22
|
- lib/optparse2/context.rb
|
|
24
23
|
- lib/optparse2/fixes.rb
|
|
25
24
|
- lib/optparse2/pathname.rb
|
data/lib/optparse2/builder.rb
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
class OptParse2
|
|
2
|
-
def switch(*pos, &block)
|
|
3
|
-
Builder.new(pos, block, self)
|
|
4
|
-
end
|
|
5
|
-
|
|
6
|
-
class Builder
|
|
7
|
-
def initialize(positional, block, optparse2)
|
|
8
|
-
@positional, @block, @optparse2 = positional, block, optparse2
|
|
9
|
-
@args = {}
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def build!
|
|
13
|
-
@optparse2.on(*@positional, **@args, &@block)
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def block(&block)
|
|
17
|
-
raise LocalJumpError unless defined? yield
|
|
18
|
-
@block = block
|
|
19
|
-
self
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def hidden(hidden = true)
|
|
23
|
-
@args[:hidden] = hidden
|
|
24
|
-
self
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def default(value = novalue=true, description: nodescription=true, &block)
|
|
28
|
-
if novalue.nil? != block.nil?
|
|
29
|
-
raise ArgumentError, "Exactly one of a positional argument or a block can be given"
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
@args[:default] = (novalue ? block : proc { value })
|
|
33
|
-
@args[:default_description] = description unless nodescription
|
|
34
|
-
self
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def key(key)
|
|
38
|
-
@args[:key] = key
|
|
39
|
-
self
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
def required(required = true)
|
|
43
|
-
@args[:required] = required
|
|
44
|
-
self
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
|