shellopts 2.0.13 → 2.0.16

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8dd7a731b489dbf650e15549d9768469ae9d6c47c6dba3ae79f4d956fea069ab
4
- data.tar.gz: 4b71aff7ba350d4616a136580857a6acd840141ed0b7463034518dcf4ae4dada
3
+ metadata.gz: 256d4f5a28f8f4028030ac17631d4e93a36584b77c96cd8090ecab8dc393f36f
4
+ data.tar.gz: 381c0515800feb0a4d2327d336ed35c43e5441915cf6aef5cb4ebd365cbe8d39
5
5
  SHA512:
6
- metadata.gz: bb5792606dd91f46b95fe786b509fd079697c87fd603c667e49740b365cafafa0cdc7b49a0a86c72cd014f9c2d88cdf74f096422e6099403042d8c34d35044b3
7
- data.tar.gz: d7f2637649b474741b70dd9334e25107586fe52eb4e4f9a289453699f334488fed60322a676ad20fcab2f0c993785ccdef89be4397055028e75d79795766b972
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
@@ -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
- @__option_values__
104
+ self.to_h(@__grammar__.options.map(&:ident))
105
105
  else
106
106
  keys.map { |key|
107
- @__option_values__.key?(key) ? [key, @__option_values__[key]] : nil
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
- # 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, 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.argument? || opt.repeatable?
198
- if opt.optional?
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 = nil)
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
- elsif !opt.argument? # Repeatable w/o argument
221
+ else
209
222
  self.instance_eval %(
210
- def #{opt.attr}(default = [])
211
- if @__option_values__.key?(:#{opt.attr})
212
- @__option_values__[:#{opt.attr}]
213
- else
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
- self.instance_eval("def #{opt.attr}=(value) @__option_values__[:#{opt.attr}] = value end")
222
- @__option_values__[opt.attr] = 0 if !opt.argument?
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|
@@ -1,3 +1,3 @@
1
1
  module ShellOpts
2
- VERSION = "2.0.13"
2
+ VERSION = "2.0.16"
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.13
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-03 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