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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3dcc11ed7e12ad87b21d8ebe019134d532b939cae79c8ed28ad7a7306995bfc2
4
- data.tar.gz: 492b927a81e1df4d1e0cfb7aa7f91fb8e456c31be7a04052e2f870ff8862871d
3
+ metadata.gz: f72b9507463f134c1c50c41330ab92e73c087764f0e378b84bff1819f52997e6
4
+ data.tar.gz: 0d46f1626d79f5a056a754467338dbb640e425d46b81c36747aab525ec69b340
5
5
  SHA512:
6
- metadata.gz: 420612dd7c3d50fff1ddff3fdfa9c87bfd05bb58f01036450a348d7ee7109cd8cf320c39382566d1d7f341b0402f09c9439dde39e20a7f732bc013c2fe60cf40
7
- data.tar.gz: a5e696e36c4206f75531d11157743462edc0ca1500b7100ac7f85fcf4a87b791b5a9758794d1181380e4da048ad8ef633aabf955803e3c3e745c63c7532a9f9c
6
+ metadata.gz: 6e647563d1b3ffc9d1f8501ae527a1de6c4069bc69cd7c81f0a456a2938f203ed22606383115a0dcf2d3ef2c71f680fa72810379cb14655608895ed10c915d04
7
+ data.tar.gz: 37805f0e018d3b842807cca56e5dcaf2906c5ad0c873171279816a658bc8b9dc6eb20faad51b4dbf4da4f557467895a4845e8104d5eb3b77f71afce748d1fea3
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class OptParse2
4
- VERSION = "0.7.7"
4
+ VERSION = "0.8.1"
5
5
  end
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
- not_matched_options.each(&nonopt)
178
-
179
- # Replace the original argv with the resulting options
180
- argv.replace not_matched_options
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.7.7
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
@@ -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
-