optparse2 0.5.3 → 0.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4b73eda58e3715e16d45898c5d4e22386a23ba2363d0708c02ea336aec51a631
4
- data.tar.gz: 777192092c696ec69bd6199fbcbd09819468dc0b06541268fa8d1a1ba4b4e389
3
+ metadata.gz: b99d0120a660e1c0831e8bb7498a7628f2e5e77bef266540ffdb7022120190e0
4
+ data.tar.gz: 7a9e744ba67a2f23e0a69fde19f30807867ac259902cbaeff477c5b64b3c3627
5
5
  SHA512:
6
- metadata.gz: c31c01a23b2d0b7020cc004d6a4dda0f24ed2dfe18464a5f8f71249502cedd425e4cb2bb341d4974e733b7e1e721b9f421e49ee022009780c3d512216df220fb
7
- data.tar.gz: e0d55f1dc1a4743a3b7d3e763272791d30895e89fcbc60ebab3554bce3f0fa1dc3dcbd0a40cef3248875d32b8d1c9da507c773e4e41e33c02065af0439e9676f
6
+ metadata.gz: f08a3c93c23ca10eb994e63317726c2c2b13407e7b80bdf1cedd095c9066679ac1c8d552c3691f3b87e9596c6c147def64a605a29794388d29766da3a5ccb4e4
7
+ data.tar.gz: 40f819a15e6f05be7dd1e0ce72ac264492405415386840fad30543ef277ff2e93b048e7963693ec682b82bc410e30406d5a85c08a551f2337bcc87d4f3c68684
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class OptParse2
4
- VERSION = "0.5.3"
4
+ VERSION = "0.6.0"
5
5
  end
data/lib/optparse2.rb CHANGED
@@ -13,11 +13,15 @@ class OptParse2
13
13
  end
14
14
  self.pos_set_banner = true
15
15
 
16
+ attr_reader :into
17
+
16
18
  def initialize(...)
17
19
  @defaults = Set[]
18
20
  @positional = []
19
21
  @required = Set[]
20
22
  @rest = nil
23
+ @into = nil
24
+ @group = nil
21
25
  self.pos_set_banner = OptParse2.pos_set_banner
22
26
  super
23
27
  end
@@ -64,7 +68,7 @@ class OptParse2
64
68
  end
65
69
 
66
70
  # Update `make_switch` to support OptParse2's keyword arguments
67
- def make_switch(opts, block, hidden: false, key: nil, default: nodefault=true, default_description: nil,
71
+ def make_switch(opts, block, hidden: false, key: @group, default: nodefault=true, default_description: nil,
68
72
  required: false)
69
73
  sw, *rest = super(opts, block)
70
74
 
@@ -102,6 +106,17 @@ class OptParse2
102
106
  on_tail("\n" + msg)
103
107
  end
104
108
 
109
+ def group(name, default: nodefault=true)
110
+ old_group, @group = @group, name
111
+ yield
112
+ if !nodefault && !@defaults.any? { |x| x.switch_name.to_sym == name }
113
+ (orig_default = default; default = proc { orig_default }) unless default.respond_to?(:call)
114
+ @defaults << Struct.new(:switch_name, :default_){ def default = default_.() }.new(name, default) # TODO: This should probably be extracted out into a class lol
115
+ end
116
+ ensure
117
+ @group = old_group
118
+ end
119
+
105
120
  def order!(argv = default_argv, into: nil, **keywords, &nonopt)
106
121
  if into.nil? && !@defaults.empty?
107
122
  raise "cannot call `order!` without an `into:` if there are default values"
@@ -113,6 +128,11 @@ class OptParse2
113
128
  into[key] = value
114
129
  end
115
130
 
131
+ # Really this shouldn't be on the class and should probably be passed to the block of each
132
+ # parameter as requested, but that requires a _significant_ amount of tinkering with `optparse`'s
133
+ # internals, which is not really in scope.
134
+ @into = already_done
135
+
116
136
  non_options = []
117
137
 
118
138
  result = super(argv, into: already_done, **keywords, &non_options.method(:<<))
@@ -156,6 +176,8 @@ class OptParse2
156
176
  end
157
177
 
158
178
  argv2
179
+ ensure
180
+ @into = nil # make sure we unset it when returning
159
181
  end
160
182
 
161
183
  module Positional
data/publish CHANGED
@@ -78,4 +78,7 @@ update_version unless $version.nil?
78
78
  ####################################################################################################
79
79
 
80
80
  system('gem', 'build', exception: true)
81
- system('gem', 'push', "#$gem-#$version.gem", exception: true) unless $dry
81
+ unless $dry
82
+ system('gem', 'push', "#$gem-#$version.gem", exception: true)
83
+ system('gem', 'install', $gem, exception: true)
84
+ end
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.5.3
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - SamW