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 +4 -4
- data/lib/optparse2/version.rb +1 -1
- data/lib/optparse2.rb +23 -1
- data/publish +4 -1
- 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: b99d0120a660e1c0831e8bb7498a7628f2e5e77bef266540ffdb7022120190e0
|
|
4
|
+
data.tar.gz: 7a9e744ba67a2f23e0a69fde19f30807867ac259902cbaeff477c5b64b3c3627
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f08a3c93c23ca10eb994e63317726c2c2b13407e7b80bdf1cedd095c9066679ac1c8d552c3691f3b87e9596c6c147def64a605a29794388d29766da3a5ccb4e4
|
|
7
|
+
data.tar.gz: 40f819a15e6f05be7dd1e0ce72ac264492405415386840fad30543ef277ff2e93b048e7963693ec682b82bc410e30406d5a85c08a551f2337bcc87d4f3c68684
|
data/lib/optparse2/version.rb
CHANGED
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:
|
|
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
|
-
|
|
81
|
+
unless $dry
|
|
82
|
+
system('gem', 'push', "#$gem-#$version.gem", exception: true)
|
|
83
|
+
system('gem', 'install', $gem, exception: true)
|
|
84
|
+
end
|