shellopts 2.0.12 → 2.0.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/TODO +20 -0
- data/lib/shellopts/program.rb +64 -20
- data/lib/shellopts/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: 253954c7f2de836c89e511dffabf3217719e778d47f74740a51c3b1099dcd07f
|
4
|
+
data.tar.gz: 4a5579e3c56674d09ba380d392e600028e6c353728994e8b2445629b772cb450
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0f0f0418361c69037a944c1e99021c32d578ed41dc239e7f9dc9f1ce94e578a137efdea3a9b96848fc0fb0b9aa1a8114153485b6ce21ceea7a3f34ceacdd197
|
7
|
+
data.tar.gz: f70644b23103d244fe06164a337839c042d6e65e1aa3dba59fa6b028cf7b0032fd694121c582142f2f3cdfbdaa12cba17464b74114bc5caf5b2aa489cde94f9a
|
data/TODO
CHANGED
@@ -1,4 +1,24 @@
|
|
1
|
+
o --option can't be escaped if on the start of a block line?
|
2
|
+
o Use require_relative
|
3
|
+
o In the following list is a command with a mandatory sub-command
|
1
4
|
|
5
|
+
list.tables!
|
6
|
+
list.uuids!
|
7
|
+
|
8
|
+
It should be rendered as
|
9
|
+
list tables|uuids
|
10
|
+
|
11
|
+
and not as
|
12
|
+
list tables
|
13
|
+
list uuids
|
14
|
+
|
15
|
+
and not as
|
16
|
+
list [tables|uuids]
|
17
|
+
|
18
|
+
o Replace -h with -? when -h is specified by the user (eg. as a shorthand for --host)
|
19
|
+
o Limit text width to -10 chars of what it is today (same as stackexchange width in characters)
|
20
|
+
o Fix formatting error in long arguments (see ms2pg)
|
21
|
+
o Macro that can be used in the SPEC for the program name (eg. <PROGRAM>)
|
2
22
|
o Ignore all text after ' # ' (doesn't conflict with option flag)
|
3
23
|
o Command aliases
|
4
24
|
o Add user-defined setions
|
data/lib/shellopts/program.rb
CHANGED
@@ -45,12 +45,12 @@ module ShellOpts
|
|
45
45
|
|
46
46
|
# These names can't be used as option or command names
|
47
47
|
RESERVED_OPTION_NAMES = %w(
|
48
|
-
is_a instance_eval instance_exec method_missing singleton_method_added
|
48
|
+
is_a to_h instance_eval instance_exec method_missing singleton_method_added
|
49
49
|
singleton_method_removed singleton_method_undefined
|
50
50
|
)
|
51
51
|
|
52
|
-
# These methods can be overridden by an option or a command (
|
53
|
-
#
|
52
|
+
# These methods can be overridden by an option or a command (this constant
|
53
|
+
# is not used - it is just for informational purposes)
|
54
54
|
OVERRIDEABLE_METHOD_NAMES = %w(
|
55
55
|
subcommand subcommand! supercommand!
|
56
56
|
)
|
@@ -96,6 +96,19 @@ module ShellOpts
|
|
96
96
|
end
|
97
97
|
end
|
98
98
|
|
99
|
+
# Returns a hash of the given options if defined. Returns all options if no
|
100
|
+
# options are given
|
101
|
+
def to_h(*keys)
|
102
|
+
keys = ::Kernel::Array(keys).flatten
|
103
|
+
if keys.empty?
|
104
|
+
@__option_values__
|
105
|
+
else
|
106
|
+
keys.map { |key|
|
107
|
+
@__option_values__.key?(key) ? [key, @__option_values__[key]] : nil
|
108
|
+
}.compact.to_h
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
99
112
|
# Subcommand identifier or nil if not present. #subcommand is often used in
|
100
113
|
# case statement to branch out to code that handles the given subcommand:
|
101
114
|
#
|
@@ -140,10 +153,10 @@ module ShellOpts
|
|
140
153
|
# Grammar object
|
141
154
|
attr_reader :__grammar__
|
142
155
|
|
143
|
-
# Hash from identifier to value. Can be Integer, Float, or String
|
144
|
-
#
|
145
|
-
#
|
146
|
-
# the
|
156
|
+
# Hash from identifier to value. Can be Integer, Float, or String depending
|
157
|
+
# on the option's type. Repeated options options without arguments have the
|
158
|
+
# number of occurences as value and with arguments the value is an array of
|
159
|
+
# the given values
|
147
160
|
attr_reader :__option_values__
|
148
161
|
|
149
162
|
# List of Option objects for the subcommand in the same order as
|
@@ -181,10 +194,23 @@ module ShellOpts
|
|
181
194
|
|
182
195
|
def __define_option_methods__
|
183
196
|
@__grammar__.options.each { |opt|
|
184
|
-
if opt.
|
185
|
-
|
197
|
+
if !opt.repeatable?
|
198
|
+
self.instance_eval %(
|
199
|
+
def #{opt.attr}?()
|
200
|
+
@__option_values__.key?(:#{opt.attr})
|
201
|
+
end
|
202
|
+
)
|
203
|
+
end
|
204
|
+
|
205
|
+
if opt.repeatable?
|
206
|
+
if opt.argument?
|
186
207
|
self.instance_eval %(
|
187
|
-
def #{opt.attr}(
|
208
|
+
def #{opt.attr}?()
|
209
|
+
(@__option_values__[:#{opt.attr}]&.size || 0) > 0
|
210
|
+
end
|
211
|
+
)
|
212
|
+
self.instance_eval %(
|
213
|
+
def #{opt.attr}(default = [])
|
188
214
|
if @__option_values__.key?(:#{opt.attr})
|
189
215
|
@__option_values__[:#{opt.attr}]
|
190
216
|
else
|
@@ -192,23 +218,41 @@ module ShellOpts
|
|
192
218
|
end
|
193
219
|
end
|
194
220
|
)
|
195
|
-
|
221
|
+
else
|
196
222
|
self.instance_eval %(
|
197
|
-
def #{opt.attr}(
|
198
|
-
|
199
|
-
|
200
|
-
|
223
|
+
def #{opt.attr}?()
|
224
|
+
(@__option_values__[:#{opt.attr}] || 0) > 0
|
225
|
+
end
|
226
|
+
)
|
227
|
+
self.instance_eval %(
|
228
|
+
def #{opt.attr}(default = 0)
|
229
|
+
if default > 0 && (@__option_values__[:#{opt.attr}] || 0) == 0
|
201
230
|
default
|
231
|
+
else
|
232
|
+
@__option_values__[:#{opt.attr}] || 0
|
202
233
|
end
|
203
234
|
end
|
204
235
|
)
|
205
|
-
else
|
206
|
-
self.instance_eval("def #{opt.attr}() @__option_values__[:#{opt.attr}] end")
|
207
236
|
end
|
208
|
-
|
209
|
-
|
237
|
+
|
238
|
+
elsif opt.argument?
|
239
|
+
self.instance_eval %(
|
240
|
+
def #{opt.attr}(default = nil)
|
241
|
+
if @__option_values__.key?(:#{opt.attr})
|
242
|
+
@__option_values__[:#{opt.attr}]
|
243
|
+
else
|
244
|
+
default
|
245
|
+
end
|
246
|
+
end
|
247
|
+
)
|
248
|
+
|
249
|
+
else
|
250
|
+
self.instance_eval %(
|
251
|
+
def #{opt.attr}()
|
252
|
+
@__option_values__.key?(:#{opt.attr})
|
253
|
+
end
|
254
|
+
)
|
210
255
|
end
|
211
|
-
self.instance_eval("def #{opt.attr}?() @__option_values__.key?(:#{opt.attr}) end")
|
212
256
|
}
|
213
257
|
|
214
258
|
@__grammar__.commands.each { |cmd|
|
data/lib/shellopts/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shellopts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Claus Rasmussen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-04-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: forward_to
|