shellopts 2.0.13 → 2.0.16
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/TODO +20 -0
- data/lib/shellopts/program.rb +50 -19
- 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: 256d4f5a28f8f4028030ac17631d4e93a36584b77c96cd8090ecab8dc393f36f
|
4
|
+
data.tar.gz: 381c0515800feb0a4d2327d336ed35c43e5441915cf6aef5cb4ebd365cbe8d39
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ac3af229c984160970034b5bbef21584bb5d78e6581f3efb2d4d9c10e9217ebde1e3cc248136224c4859d9a73ded08fc1a6782ebddb55a2d8eff1b5d480c42f9
|
7
|
+
data.tar.gz: 855d30fcd66f441a09ab53d50284a11e2a24bcd8c24b9c5573e1783c571005ab6b7a383aefbd0d9883893207550fe9bd880def44e361f000c87289a3476fe48f
|
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
@@ -101,10 +101,10 @@ module ShellOpts
|
|
101
101
|
def to_h(*keys)
|
102
102
|
keys = ::Kernel::Array(keys).flatten
|
103
103
|
if keys.empty?
|
104
|
-
@
|
104
|
+
self.to_h(@__grammar__.options.map(&:ident))
|
105
105
|
else
|
106
106
|
keys.map { |key|
|
107
|
-
|
107
|
+
self.__send__("#{key}?".to_sym) ? [key, self.__send__(key)] : nil
|
108
108
|
}.compact.to_h
|
109
109
|
end
|
110
110
|
end
|
@@ -153,10 +153,10 @@ module ShellOpts
|
|
153
153
|
# Grammar object
|
154
154
|
attr_reader :__grammar__
|
155
155
|
|
156
|
-
# Hash from identifier to value. Can be Integer, Float, or String
|
157
|
-
#
|
158
|
-
#
|
159
|
-
#
|
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, repeated option with arguments have the
|
159
|
+
# array of values as value
|
160
160
|
attr_reader :__option_values__
|
161
161
|
|
162
162
|
# List of Option objects for the subcommand in the same order as
|
@@ -194,10 +194,23 @@ module ShellOpts
|
|
194
194
|
|
195
195
|
def __define_option_methods__
|
196
196
|
@__grammar__.options.each { |opt|
|
197
|
-
if opt.
|
198
|
-
|
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?
|
207
|
+
self.instance_eval %(
|
208
|
+
def #{opt.attr}?()
|
209
|
+
(@__option_values__[:#{opt.attr}]&.size || 0) > 0
|
210
|
+
end
|
211
|
+
)
|
199
212
|
self.instance_eval %(
|
200
|
-
def #{opt.attr}(default =
|
213
|
+
def #{opt.attr}(default = [])
|
201
214
|
if @__option_values__.key?(:#{opt.attr})
|
202
215
|
@__option_values__[:#{opt.attr}]
|
203
216
|
else
|
@@ -205,23 +218,41 @@ module ShellOpts
|
|
205
218
|
end
|
206
219
|
end
|
207
220
|
)
|
208
|
-
|
221
|
+
else
|
209
222
|
self.instance_eval %(
|
210
|
-
def #{opt.attr}(
|
211
|
-
|
212
|
-
|
213
|
-
|
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
|
214
230
|
default
|
231
|
+
else
|
232
|
+
@__option_values__[:#{opt.attr}] || 0
|
215
233
|
end
|
216
234
|
end
|
217
235
|
)
|
218
|
-
else
|
219
|
-
self.instance_eval("def #{opt.attr}() @__option_values__[:#{opt.attr}] end")
|
220
236
|
end
|
221
|
-
|
222
|
-
|
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
|
+
)
|
223
255
|
end
|
224
|
-
self.instance_eval("def #{opt.attr}?() @__option_values__.key?(:#{opt.attr}) end")
|
225
256
|
}
|
226
257
|
|
227
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.16
|
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-04-
|
11
|
+
date: 2022-04-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: forward_to
|