shellopts 2.0.14 → 2.0.15

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: 2101f633ad0e166982b108842a83f91b3d216869f9fe3d6ac7ecea5256f2b437
4
- data.tar.gz: da77f695902e5e921e598dd8d1327af4ce07ffe7b9cfadb88fe1b0889b95b4e0
3
+ metadata.gz: 253954c7f2de836c89e511dffabf3217719e778d47f74740a51c3b1099dcd07f
4
+ data.tar.gz: 4a5579e3c56674d09ba380d392e600028e6c353728994e8b2445629b772cb450
5
5
  SHA512:
6
- metadata.gz: 36dbd8d33d74a5b985463df5fb514501c2881881bdd68f1fa479c7ecac3de2bc4a2bc3a713acfe735d3e53ccdde10f5abf5ecc066d370fa8e795a77e290f9988
7
- data.tar.gz: b364c8d00de2f7ece58d3c721ef3d4f40a892a232aa39a0c94df2b7ef37cf86e78c99df25c07e8802b0e48640ec928c4157bd89a2cb0851955484ed5957733ca
6
+ metadata.gz: d0f0f0418361c69037a944c1e99021c32d578ed41dc239e7f9dc9f1ce94e578a137efdea3a9b96848fc0fb0b9aa1a8114153485b6ce21ceea7a3f34ceacdd197
7
+ data.tar.gz: f70644b23103d244fe06164a337839c042d6e65e1aa3dba59fa6b028cf7b0032fd694121c582142f2f3cdfbdaa12cba17464b74114bc5caf5b2aa489cde94f9a
data/TODO CHANGED
@@ -1,4 +1,5 @@
1
-
1
+ o --option can't be escaped if on the start of a block line?
2
+ o Use require_relative
2
3
  o In the following list is a command with a mandatory sub-command
3
4
 
4
5
  list.tables!
@@ -14,7 +15,6 @@ o In the following list is a command with a mandatory sub-command
14
15
  and not as
15
16
  list [tables|uuids]
16
17
 
17
-
18
18
  o Replace -h with -? when -h is specified by the user (eg. as a shorthand for --host)
19
19
  o Limit text width to -10 chars of what it is today (same as stackexchange width in characters)
20
20
  o Fix formatting error in long arguments (see ms2pg)
@@ -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
- # depending on the option's type. Repeated options options without
158
- # arguments have the number of occurences as the value, with arguments
159
- # the value is an array of the given values
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
160
160
  attr_reader :__option_values__
161
161
 
162
162
  # List of Option objects for the subcommand in the same order as
@@ -194,7 +194,48 @@ module ShellOpts
194
194
 
195
195
  def __define_option_methods__
196
196
  @__grammar__.options.each { |opt|
197
- if opt.argument?
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
+ )
212
+ self.instance_eval %(
213
+ def #{opt.attr}(default = [])
214
+ if @__option_values__.key?(:#{opt.attr})
215
+ @__option_values__[:#{opt.attr}]
216
+ else
217
+ default
218
+ end
219
+ end
220
+ )
221
+ else
222
+ self.instance_eval %(
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
230
+ default
231
+ else
232
+ @__option_values__[:#{opt.attr}] || 0
233
+ end
234
+ end
235
+ )
236
+ end
237
+
238
+ elsif opt.argument?
198
239
  self.instance_eval %(
199
240
  def #{opt.attr}(default = nil)
200
241
  if @__option_values__.key?(:#{opt.attr})
@@ -205,26 +246,13 @@ module ShellOpts
205
246
  end
206
247
  )
207
248
 
208
- elsif opt.repeatable?
249
+ else
209
250
  self.instance_eval %(
210
- def #{opt.attr}(default = 0)
211
- if default > 0 && @__option_values__[:#{opt.attr}] == 0
212
- default
213
- else
214
- @__option_values__[:#{opt.attr}]
215
- end
251
+ def #{opt.attr}()
252
+ @__option_values__.key?(:#{opt.attr})
216
253
  end
217
254
  )
218
- else
219
- self.instance_eval("def #{opt.attr}() @__option_values__[:#{opt.attr}] end")
220
255
  end
221
-
222
- if opt.argument? || opt.repeatable?
223
- self.instance_eval("def #{opt.attr}=(value) @__option_values__[:#{opt.attr}] = value end")
224
- @__option_values__[opt.attr] = 0 if !opt.argument?
225
- end
226
-
227
- self.instance_eval("def #{opt.attr}?() @__option_values__.key?(:#{opt.attr}) end")
228
256
  }
229
257
 
230
258
  @__grammar__.commands.each { |cmd|
@@ -1,3 +1,3 @@
1
1
  module ShellOpts
2
- VERSION = "2.0.14"
2
+ VERSION = "2.0.15"
3
3
  end
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.14
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-04-05 00:00:00.000000000 Z
11
+ date: 2022-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: forward_to