clasp-ruby 0.22.1 → 0.23.0.2

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.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +63 -52
  3. data/examples/cr-example.rb +16 -16
  4. data/examples/flag_and_option_specifications.md +25 -25
  5. data/examples/flag_and_option_specifications.rb +6 -6
  6. data/examples/show_usage_and_version.md +5 -5
  7. data/examples/show_usage_and_version.rb +1 -1
  8. data/examples/simple_command_line_no_specifications.rb +1 -1
  9. data/lib/clasp/arguments.rb +543 -531
  10. data/lib/clasp/clasp.rb +7 -7
  11. data/lib/clasp/cli.rb +140 -135
  12. data/lib/clasp/doc_.rb +3 -3
  13. data/lib/clasp/old_module.rb +3 -3
  14. data/lib/clasp/specifications.rb +337 -333
  15. data/lib/clasp/util/exceptions.rb +17 -17
  16. data/lib/clasp/util/value_parser.rb +97 -97
  17. data/lib/clasp/version.rb +15 -15
  18. data/lib/clasp-ruby.rb +3 -2
  19. data/lib/clasp.rb +3 -2
  20. data/test/scratch/test_list_command_line.rb +6 -6
  21. data/test/scratch/test_specifications.rb +14 -14
  22. data/test/scratch/test_usage.rb +6 -6
  23. data/test/scratch/test_usage_from_DATA.rb +1 -1
  24. data/test/scratch/test_usage_with_duplicate_specifications.rb +6 -6
  25. data/test/unit/tc_ARGV_rewrite.rb +36 -38
  26. data/test/unit/tc_arguments_1.rb +702 -656
  27. data/test/unit/tc_arguments_2.rb +52 -53
  28. data/test/unit/tc_arguments_3.rb +77 -77
  29. data/test/unit/tc_arguments_inspect.rb +55 -56
  30. data/test/unit/tc_cli.rb +4 -4
  31. data/test/unit/tc_default_value.rb +91 -91
  32. data/test/unit/tc_defaults_1.rb +38 -38
  33. data/test/unit/tc_examples_Arguments.rb +130 -132
  34. data/test/unit/tc_extras.rb +24 -26
  35. data/test/unit/tc_option_required.rb +38 -39
  36. data/test/unit/tc_option_value_aliases.rb +44 -44
  37. data/test/unit/tc_specifications.rb +7 -8
  38. data/test/unit/tc_typed_options.rb +204 -204
  39. data/test/unit/tc_usage.rb +112 -55
  40. data/test/unit/tc_with_action.rb +23 -24
  41. data/test/unit/ts_all.rb +1 -1
  42. metadata +8 -7
@@ -5,13 +5,13 @@
5
5
  # Purpose: Argument specification classes
6
6
  #
7
7
  # Created: 25th October 2014
8
- # Updated: 29th April 2019
8
+ # Updated: 20th January 2024
9
9
  #
10
10
  # Home: http://github.com/synesissoftware/CLASP.Ruby
11
11
  #
12
12
  # Author: Matthew Wilson
13
13
  #
14
- # Copyright (c) 2014-2019, Matthew Wilson and Synesis Software
14
+ # Copyright (c) 2014-2024, Matthew Wilson and Synesis Software
15
15
  # All rights reserved.
16
16
  #
17
17
  # Redistribution and use in source and binary forms, with or without
@@ -54,327 +54,329 @@
54
54
 
55
55
  module CLASP
56
56
 
57
+
57
58
  # ######################################################################## #
58
59
  # classes
59
60
 
60
61
  # @!visibility private
61
62
  class SpecificationBase # :nodoc: all
62
63
 
63
- private
64
- # @!visibility private
65
- def check_arity_(blk, range, label) # :nodoc:
64
+ private
65
+ # @!visibility private
66
+ def check_arity_(blk, range, label) # :nodoc:
66
67
 
67
- raise ArgumentError, "block must be a #{Proc}; #{blk.class} given" unless blk.nil? || Proc === blk
68
+ raise ArgumentError, "block must be a #{Proc}; #{blk.class} given" unless blk.nil? || Proc === blk
68
69
 
69
- if blk
70
+ if blk
70
71
 
71
- case blk.arity
72
- when range
72
+ case blk.arity
73
+ when range
73
74
 
74
- ;
75
- else
75
+ ;
76
+ else
76
77
 
77
- msg = "wrong arity for #{label}"
78
+ msg = "wrong arity for #{label}"
78
79
 
79
- if $DEBUG
80
+ if $DEBUG
80
81
 
81
- raise ArgumentError, msg
82
- else
82
+ raise ArgumentError, msg
83
+ else
83
84
 
84
- warn msg
85
- end
86
- end
87
- end
88
- end
89
- public
85
+ warn msg
86
+ end
87
+ end
88
+ end
89
+ end
90
+ public
90
91
  end
91
92
 
92
93
  # A class that represents the specification for a command-line flag
93
94
  class FlagSpecification < SpecificationBase
94
95
 
95
- # Creates a FlagSpecification instance from the given name, aliases, and help
96
- #
97
- # === Signature
98
- #
99
- # * *Parameters*
100
- # - +name+ (+String+) The name, or long-form, of the flag
101
- # - +aliases+ (+Array+) 0 or more strings specifying short-form or option-value aliases
102
- # - +help+ (+String+) The help string, which may be +nil+
103
- # - +extras+ An application-defined additional parameter. If +nil+, it is assigned an empty +Hash+
104
- #
105
- # * *Block* An optional block that is called when a matching flag argument is found
106
- #
107
- # *NOTE:* Users should prefer the +CLASP::Flag()+ method
108
- def initialize(name, aliases, help, extras = nil, &blk)
96
+ # Creates a FlagSpecification instance from the given name, aliases, and help
97
+ #
98
+ # === Signature
99
+ #
100
+ # * *Parameters*
101
+ # - +name+ (+String+) The name, or long-form, of the flag
102
+ # - +aliases+ (+Array+) 0 or more strings specifying short-form or option-value aliases
103
+ # - +help+ (+String+) The help string, which may be +nil+
104
+ # - +extras+ An application-defined additional parameter. If +nil+, it is assigned an empty +Hash+
105
+ #
106
+ # * *Block* An optional block that is called when a matching flag argument is found
107
+ #
108
+ # *NOTE:* Users should prefer the +CLASP::Flag()+ method
109
+ def initialize(name, aliases, help, extras = nil, &blk)
109
110
 
110
- check_arity_(blk, 0..3, "flag")
111
+ check_arity_(blk, 0..3, "flag")
111
112
 
112
- @name = name
113
- @aliases = (aliases || []).select { |a| a and not a.empty? }
114
- @help = help
115
- @extras = extras || {}
116
- @action = blk
117
- end
113
+ @name = name
114
+ @aliases = (aliases || []).select { |a| a and not a.empty? }
115
+ @help = help
116
+ @extras = extras || {}
117
+ @action = blk
118
+ end
118
119
 
119
- # The flag's name string
120
- attr_reader :name
121
- # The flag's aliases array
122
- attr_reader :aliases
123
- # The flag's help string
124
- attr_reader :help
125
- # The flag's extras
126
- attr_reader :extras
120
+ # The flag's name string
121
+ attr_reader :name
122
+ # The flag's aliases array
123
+ attr_reader :aliases
124
+ # The flag's help string
125
+ attr_reader :help
126
+ # The flag's extras
127
+ attr_reader :extras
127
128
 
128
- # (Proc) The procedure
129
- attr_reader :action
129
+ # (Proc) The procedure
130
+ attr_reader :action
130
131
 
131
- # @!visibility private
132
- def action=(blk) # :nodoc: all
132
+ # @!visibility private
133
+ def action=(blk) # :nodoc: all
133
134
 
134
- check_arity_(blk, 0..3, "flag")
135
+ check_arity_(blk, 0..3, "flag")
135
136
 
136
- @action = blk
137
- end
137
+ @action = blk
138
+ end
138
139
 
139
- # String form of the flag
140
- def to_s
140
+ # String form of the flag
141
+ def to_s
141
142
 
142
- "{#{name}; aliases=#{aliases.join(', ')}; help='#{help}'; extras=#{extras}}"
143
- end
143
+ "{#{name}; aliases=#{aliases.join(', ')}; help='#{help}'; extras=#{extras}}"
144
+ end
144
145
 
145
- # @!visibility private
146
- def eql? rhs # :nodoc:
146
+ # @!visibility private
147
+ def eql? rhs # :nodoc:
147
148
 
148
- case rhs
149
- when self.class
149
+ case rhs
150
+ when self.class
150
151
 
151
- return true if equal?(rhs)
152
- else
152
+ return true if equal?(rhs)
153
+ else
153
154
 
154
- return false
155
- end
155
+ return false
156
+ end
156
157
 
157
- return false unless name == rhs.name
158
- return false unless aliases == rhs.aliases
159
- return false unless help == rhs.help
160
- return false unless extras == rhs.extras
158
+ return false unless name == rhs.name
159
+ return false unless aliases == rhs.aliases
160
+ return false unless help == rhs.help
161
+ return false unless extras == rhs.extras
161
162
 
162
- return true
163
- end
163
+ return true
164
+ end
164
165
 
165
- # Compares instance against another FlagSpecification or against a name (String)
166
- def == rhs
166
+ # Compares instance against another FlagSpecification or against a name (String)
167
+ def == rhs
167
168
 
168
- case rhs
169
- when self.class
169
+ case rhs
170
+ when self.class
170
171
 
171
- return self.eql? rhs
172
- when String
172
+ return self.eql? rhs
173
+ when String
173
174
 
174
- return name == rhs
175
- else
175
+ return name == rhs
176
+ else
176
177
 
177
- false
178
- end
179
- end
178
+ false
179
+ end
180
+ end
180
181
 
181
182
  private
182
- @@Help_ = self.new('--help', [], 'shows this help and terminates')
183
- @@Version_ = self.new('--version', [], 'shows version and terminates')
183
+ @@Help_ = self.new('--help', [], 'shows this help and terminates')
184
+ @@Version_ = self.new('--version', [], 'shows version and terminates')
184
185
  public
185
- # An instance of FlagSpecification that provides default '--help' information
186
- #
187
- # If you wish to specify +extras+ or attach a block, you may do so
188
- def self.Help(extras = nil, &blk)
186
+ # An instance of FlagSpecification that provides default '--help' information
187
+ #
188
+ # If you wish to specify +extras+ or attach a block, you may do so
189
+ def self.Help(extras = nil, &blk)
189
190
 
190
- h = @@Help_
191
+ h = @@Help_
191
192
 
192
- if extras || blk
193
+ if extras || blk
193
194
 
194
- return self.new(h.name, h.aliases, h.help, extras, &blk)
195
- end
195
+ return self.new(h.name, h.aliases, h.help, extras, &blk)
196
+ end
196
197
 
197
- h
198
- end
198
+ h
199
+ end
199
200
 
200
- # An instance of FlagSpecification that provides default '--version' information
201
- #
202
- # If you wish to specify +extras+ or attach a block, you may do so
203
- def self.Version(extras = nil, &blk)
201
+ # An instance of FlagSpecification that provides default '--version' information
202
+ #
203
+ # If you wish to specify +extras+ or attach a block, you may do so
204
+ def self.Version(extras = nil, &blk)
204
205
 
205
- h = @@Version_
206
+ h = @@Version_
206
207
 
207
- if extras || blk
208
+ if extras || blk
208
209
 
209
- return self.new(h.name, h.aliases, h.help, extras, &blk)
210
- end
210
+ return self.new(h.name, h.aliases, h.help, extras, &blk)
211
+ end
211
212
 
212
- h
213
- end
213
+ h
214
+ end
214
215
  end
215
216
 
216
217
  # A class that represents the specification for a command-line option
217
218
  class OptionSpecification < SpecificationBase
218
219
 
219
- # Creates an OptionSpecification instance from the given name, aliases, help,
220
- # values_range, and default_value
221
- #
222
- # === Signature
223
- #
224
- # * *Parameters*
225
- # - +name+ (+String+) The name, or long-form, of the option
226
- # - +aliases+ (+Array+) 0 or more strings specifying short-form or option-value aliases
227
- # - +help+ (+String+) The help string, which may be +nil+
228
- # - +values_range+ (+Array+) 0 or more strings specifying values supported by the option
229
- # - +default_value+ (+String+) The default value of the option, which will be used in the case where an option is specified without a value. May be +nil+
230
- # - +required+ (boolean) Whether the option is required. May be +nil+
231
- # - +required_message+ (::String) Message to be used when reporting that a required option is missing. May be +nil+ in which case a message of the form "<option-name> not specified; use --help for usage". If begins with the nul character ("\0"), then is used in the place of the <option-name> and placed into the rest of the standard form message
232
- # - +constraint+ (Hash) Constraint to be applied to the parsed values of options matching this specification. NOTE: only integer constraints are supported in the current version
233
- # - +extras+ An application-defined additional parameter. If +nil+, it is assigned an empty +Hash+
234
- #
235
- # * *Block* An optional block that is called when a matching option argument is found
236
- #
237
- # *NOTE:* Users should prefer the +CLASP::Option()+ method
238
- def initialize(name, aliases, help, values_range, default_value, required, required_message, constraint, extras = nil, &blk)
239
-
240
- check_arity_(blk, 0..3, "option")
241
-
242
- @name = name
243
- @aliases = (aliases || []).select { |a| a and not a.empty? }
244
- @help = help
245
- @values_range = values_range || []
246
- @default_value = default_value
247
- @required = required
248
- @required_message = nil
249
- @constraint = constraint || {}
250
- @extras = extras || {}
251
- @action = blk
252
-
253
- rm_name = nil
254
-
255
- if required_message
256
-
257
- if "\0" == required_message[0]
258
-
259
- rm_name = required_message[1..-1]
260
- end
261
- else
262
-
263
- rm_name = "'#{name}'"
264
- end
265
-
266
- if rm_name
267
-
268
- required_message = "#{rm_name} not specified; use --help for usage"
269
- end
270
-
271
- @required_message = required_message
272
- end
273
-
274
- # The option's name string
275
- attr_reader :name
276
- # The option's aliases array
277
- attr_reader :aliases
278
- # The option's help string
279
- attr_reader :help
280
- # The range of values supported by the option
281
- attr_reader :values_range
282
- # The default value of the option
283
- attr_reader :default_value
284
- # Indicates whether the option is required
285
- def required?; @required; end
286
- # The message to be used when reporting that a required option is missing
287
- attr_reader :required_message
288
- # The value constraint
289
- attr_reader :constraint
290
- # The option's extras
291
- attr_reader :extras
292
-
293
- # (Proc) The procedure
294
- attr_reader :action
295
-
296
- # @!visibility private
297
- def action=(blk) # :nodoc: all
298
-
299
- check_arity_(blk, 0..3, "flag")
300
-
301
- @action = blk
302
- end
303
-
304
- # String form of the option
305
- def to_s
306
-
307
- "{#{name}; aliases=#{aliases.join(', ')}; values_range=[ #{values_range.join(', ')} ]; default_value='#{default_value}'; help='#{help}'; required?=#{required?}; required_message=#{required_message}; constraint=#{constraint}; extras=#{extras}}"
308
- end
309
-
310
- # @!visibility private
311
- def eql? rhs # :nodoc:
312
-
313
- case rhs
314
- when self.class
315
-
316
- return true if equal?(rhs)
317
- else
318
-
319
- return false
320
- end
321
-
322
- return false unless name == rhs.name
323
- return false unless aliases == rhs.aliases
324
- return false unless help == rhs.help
325
- return false unless values_range == rhs.values_range
326
- return false unless default_value == rhs.default_value
327
- return false unless required? == rhs.required?
328
- return false unless required_message == rhs.required_message
329
- return false unless extras == rhs.extras
330
-
331
- return true
332
- end
333
-
334
- # Compares instance against another OptionSpecification or against a name (String)
335
- def == rhs
220
+ # Creates an OptionSpecification instance from the given name, aliases, help,
221
+ # values_range, and default_value
222
+ #
223
+ # === Signature
224
+ #
225
+ # * *Parameters*
226
+ # - +name+ (+String+) The name, or long-form, of the option
227
+ # - +aliases+ (+Array+) 0 or more strings specifying short-form or option-value aliases
228
+ # - +help+ (+String+) The help string, which may be +nil+
229
+ # - +values_range+ (+Array+) 0 or more strings specifying values supported by the option
230
+ # - +default_value+ (+String+) The default value of the option, which will be used in the case where an option is specified without a value. May be +nil+
231
+ # - +required+ (boolean) Whether the option is required. May be +nil+
232
+ # - +required_message+ (::String) Message to be used when reporting that a required option is missing. May be +nil+ in which case a message of the form "<option-name> not specified; use --help for usage". If begins with the nul character ("\0"), then is used in the place of the <option-name> and placed into the rest of the standard form message
233
+ # - +constraint+ (Hash) Constraint to be applied to the parsed values of options matching this specification. NOTE: only integer constraints are supported in the current version
234
+ # - +extras+ An application-defined additional parameter. If +nil+, it is assigned an empty +Hash+
235
+ #
236
+ # * *Block* An optional block that is called when a matching option argument is found
237
+ #
238
+ # *NOTE:* Users should prefer the +CLASP::Option()+ method
239
+ def initialize(name, aliases, help, values_range, default_value, required, required_message, constraint, extras = nil, &blk)
240
+
241
+ check_arity_(blk, 0..3, "option")
242
+
243
+ @name = name
244
+ @aliases = (aliases || []).select { |a| a and not a.empty? }
245
+ @help = help
246
+ @values_range = values_range || []
247
+ @default_value = default_value
248
+ @required = required
249
+ @required_message = nil
250
+ @constraint = constraint || {}
251
+ @extras = extras || {}
252
+ @action = blk
253
+
254
+ rm_name = nil
255
+
256
+ if required_message
257
+
258
+ if "\0" == required_message[0]
259
+
260
+ rm_name = required_message[1..-1]
261
+ end
262
+ else
263
+
264
+ rm_name = "'#{name}'"
265
+ end
266
+
267
+ if rm_name
268
+
269
+ required_message = "#{rm_name} not specified; use --help for usage"
270
+ end
271
+
272
+ @required_message = required_message
273
+ end
274
+
275
+ # The option's name string
276
+ attr_reader :name
277
+ # The option's aliases array
278
+ attr_reader :aliases
279
+ # The option's help string
280
+ attr_reader :help
281
+ # The range of values supported by the option
282
+ attr_reader :values_range
283
+ # The default value of the option
284
+ attr_reader :default_value
285
+ # Indicates whether the option is required
286
+ def required?; @required; end
287
+ # The message to be used when reporting that a required option is missing
288
+ attr_reader :required_message
289
+ # The value constraint
290
+ attr_reader :constraint
291
+ # The option's extras
292
+ attr_reader :extras
293
+
294
+ # (Proc) The procedure
295
+ attr_reader :action
296
+
297
+ # @!visibility private
298
+ def action=(blk) # :nodoc: all
299
+
300
+ check_arity_(blk, 0..3, "flag")
301
+
302
+ @action = blk
303
+ end
304
+
305
+ # String form of the option
306
+ def to_s
307
+
308
+ "{#{name}; aliases=#{aliases.join(', ')}; values_range=[ #{values_range.join(', ')} ]; default_value='#{default_value}'; help='#{help}'; required?=#{required?}; required_message=#{required_message}; constraint=#{constraint}; extras=#{extras}}"
309
+ end
310
+
311
+ # @!visibility private
312
+ def eql? rhs # :nodoc:
313
+
314
+ case rhs
315
+ when self.class
316
+
317
+ return true if equal?(rhs)
318
+ else
319
+
320
+ return false
321
+ end
322
+
323
+ return false unless name == rhs.name
324
+ return false unless aliases == rhs.aliases
325
+ return false unless help == rhs.help
326
+ return false unless values_range == rhs.values_range
327
+ return false unless default_value == rhs.default_value
328
+ return false unless required? == rhs.required?
329
+ return false unless required_message == rhs.required_message
330
+ return false unless extras == rhs.extras
331
+
332
+ return true
333
+ end
334
+
335
+ # Compares instance against another OptionSpecification or against a name (String)
336
+ def == rhs
336
337
 
337
- case rhs
338
- when self.class
338
+ case rhs
339
+ when self.class
339
340
 
340
- return self.eql? rhs
341
- when String
341
+ return self.eql? rhs
342
+ when String
342
343
 
343
- return name == rhs
344
- else
344
+ return name == rhs
345
+ else
345
346
 
346
- false
347
- end
348
- end
347
+ false
348
+ end
349
+ end
349
350
  end
350
351
 
351
352
  # A class that represents an explicit alias for a flag or an option
352
353
  class AliasSpecification
353
354
 
354
- def initialize(name, aliases)
355
+ def initialize(name, aliases)
355
356
 
356
- @name = name
357
- @aliases = (aliases || []).select { |a| a and not a.empty? }
358
- @extras = nil
359
- @help = nil
360
- end
357
+ @name = name
358
+ @aliases = (aliases || []).select { |a| a and not a.empty? }
359
+ @extras = nil
360
+ @help = nil
361
+ end
361
362
 
362
- # The alias' name string
363
- attr_reader :name
364
- # The alias' aliases array
365
- attr_reader :aliases
366
- # The flag's help string
367
- attr_reader :help
368
- # The flag's extras
369
- attr_reader :extras
363
+ # The alias' name string
364
+ attr_reader :name
365
+ # The alias' aliases array
366
+ attr_reader :aliases
367
+ # The flag's help string
368
+ attr_reader :help
369
+ # The flag's extras
370
+ attr_reader :extras
370
371
 
371
- # String form of the option
372
- def to_s
372
+ # String form of the option
373
+ def to_s
373
374
 
374
- "{#{name}; aliases=#{aliases.join(', ')}}"
375
- end
375
+ "{#{name}; aliases=#{aliases.join(', ')}}"
376
+ end
376
377
  end
377
378
 
379
+
378
380
  # ######################################################################## #
379
381
  # functions
380
382
 
@@ -396,38 +398,38 @@ end
396
398
  # * *Block* An optional block that is called when a matching flag argument is found
397
399
  def CLASP.Flag(name, options = {}, &blk)
398
400
 
399
- aliases = nil
400
- help = nil
401
- extras = nil
401
+ aliases = nil
402
+ help = nil
403
+ extras = nil
402
404
 
403
- options.each do |k, v|
405
+ options.each do |k, v|
404
406
 
405
- case k
406
- when Symbol
407
- case k
408
- when :alias
407
+ case k
408
+ when Symbol
409
+ case k
410
+ when :alias
409
411
 
410
- aliases = [ v ] if v
411
- when :aliases
412
+ aliases = [ v ] if v
413
+ when :aliases
412
414
 
413
- aliases = v unless aliases
414
- when :help
415
+ aliases = v unless aliases
416
+ when :help
415
417
 
416
- help = v
417
- when :extras
418
+ help = v
419
+ when :extras
418
420
 
419
- extras = v
420
- else
421
+ extras = v
422
+ else
421
423
 
422
- raise ArgumentError, "invalid option for flag: '#{k}' => '#{v}'"
423
- end
424
- else
424
+ raise ArgumentError, "invalid option for flag: '#{k}' => '#{v}'"
425
+ end
426
+ else
425
427
 
426
- raise ArgumentError, "invalid option type for flag: '#{k}' (#{k.class}) => '#{v}'"
427
- end
428
- end
428
+ raise ArgumentError, "invalid option type for flag: '#{k}' (#{k.class}) => '#{v}'"
429
+ end
430
+ end
429
431
 
430
- CLASP::FlagSpecification.new(name, aliases, help, extras, &blk)
432
+ CLASP::FlagSpecification.new(name, aliases, help, extras, &blk)
431
433
  end
432
434
 
433
435
  # Generator method that obtains a CLASP::OptionSpecification according to the given
@@ -446,103 +448,105 @@ end
446
448
  # - +:default+ [DEPRECATED] Alternative to +:default_value+
447
449
  # - +:extras+ An application-defined object, usually a hash of custom attributes
448
450
  # - +:help+ (::String) A help string
449
- # - +required+ (boolean) Whether the option is required. May be +nil+
450
- # - +required_message+ (::String) Message to be used when reporting that a required option is missing. May be +nil+ in which case a message of the form "<option-name> not specified; use --help for usage". If begins with the nul character ("\0"), then is used in the place of the <option-name> and placed into the rest of the standard form message
451
- # - +extras+ An application-defined additional parameter. If +nil+, it is assigned an empty +Hash+.
452
- # - +constraint+ (Hash) Constraint to be applied to the parsed values of options matching this specification. NOTE: only integer constraints are supported in the current version
451
+ # - +:required+ (boolean) Whether the option is required. May be +nil+
452
+ # - +:required_message+ (::String) Message to be used when reporting that a required option is missing. May be +nil+ in which case a message of the form "<option-name> not specified; use --help for usage". If begins with the nul character ("\0"), then is used in the place of the <option-name> and placed into the rest of the standard form message
453
+ # - +:extras+ An application-defined additional parameter. If +nil+, it is assigned an empty +Hash+.
454
+ # - +:constraint+ (Hash) Constraint to be applied to the parsed values of options matching this specification. NOTE: only integer constraints are supported in the current version
453
455
  # - +:values_range+ (::Array) An array defining the accepted values for the option
454
456
  # - +:values+ [DEPRECATED] Alternative to +:values_range+
455
457
  #
456
458
  # * *Block* An optional block that is called when a matching option argument is found
457
459
  def CLASP.Option(name, options = {}, &blk)
458
460
 
459
- aliases = nil
460
- help = nil
461
- values_range = nil
462
- default_value = nil
463
- required = false
464
- require_message = nil
465
- constraint = nil
466
- extras = nil
461
+ aliases = nil
462
+ help = nil
463
+ values_range = nil
464
+ default_value = nil
465
+ required = false
466
+ require_message = nil
467
+ constraint = nil
468
+ extras = nil
467
469
 
468
- options.each do |k, v|
470
+ options.each do |k, v|
469
471
 
470
- case k
471
- when Symbol
472
- case k
473
- when :alias
472
+ case k
473
+ when Symbol
474
+ case k
475
+ when :alias
474
476
 
475
- aliases = [ v ] if v
476
- when :aliases
477
+ aliases = [ v ] if v
478
+ when :aliases
477
479
 
478
- aliases = v unless aliases
479
- when :help
480
+ aliases = v unless aliases
481
+ when :help
480
482
 
481
- help = v
482
- when :values_range, :values
483
+ help = v
484
+ when :values_range, :values
483
485
 
484
- values_range = v
485
- when :default_value, :default
486
+ values_range = v
487
+ when :default_value, :default
486
488
 
487
- default_value = v
488
- when :required
489
+ default_value = v
490
+ when :required
489
491
 
490
- required = v
491
- when :required_message
492
+ required = v
493
+ when :required_message
492
494
 
493
- require_message = v
494
- when :extras
495
+ require_message = v
496
+ when :extras
495
497
 
496
- extras = v
497
- when :constraint
498
+ extras = v
499
+ when :constraint
498
500
 
499
- constraint = v
500
- else
501
+ constraint = v
502
+ else
501
503
 
502
- raise ArgumentError, "invalid option for option: '#{k}' => '#{v}'"
503
- end
504
- else
504
+ raise ArgumentError, "invalid option for option: '#{k}' => '#{v}'"
505
+ end
506
+ else
505
507
 
506
- raise ArgumentError, "invalid option type for option: '#{k}' (#{k.class}) => '#{v}'"
507
- end
508
- end
508
+ raise ArgumentError, "invalid option type for option: '#{k}' (#{k.class}) => '#{v}'"
509
+ end
510
+ end
509
511
 
510
- CLASP::OptionSpecification.new(name, aliases, help, values_range, default_value, required, require_message, constraint, extras, &blk)
512
+ CLASP::OptionSpecification.new(name, aliases, help, values_range, default_value, required, require_message, constraint, extras, &blk)
511
513
  end
512
514
 
513
515
  def CLASP.Alias(name, *args)
514
516
 
515
- options = args.pop if args[-1].is_a?(::Hash)
516
- options ||= {}
517
+ options = args.pop if args[-1].is_a?(::Hash)
518
+ options ||= {}
517
519
 
518
- if options[:alias]
520
+ if options[:alias]
519
521
 
520
- aliases = [ options[:alias] ]
521
- elsif options[:aliases]
522
+ aliases = [ options[:alias] ]
523
+ elsif options[:aliases]
522
524
 
523
- aliases = options[:aliases]
524
- else
525
+ aliases = options[:aliases]
526
+ else
525
527
 
526
- aliases = args
527
- end
528
+ aliases = args
529
+ end
528
530
 
529
- CLASP::AliasSpecification.new name, aliases
531
+ CLASP::AliasSpecification.new name, aliases
530
532
  end
531
533
 
534
+
532
535
  # ######################################################################## #
533
536
  # backwards-compatible
534
537
 
535
- Alias = AliasSpecification
536
- Flag = FlagSpecification
537
- FlagAlias = FlagSpecification
538
- Option = OptionSpecification
539
- OptionAlias = OptionSpecification
538
+ Alias = AliasSpecification
539
+ Flag = FlagSpecification
540
+ FlagAlias = FlagSpecification
541
+ Option = OptionSpecification
542
+ OptionAlias = OptionSpecification
543
+
540
544
 
541
545
  # ######################################################################## #
542
546
  # module
543
547
 
544
548
  end # module CLASP
545
549
 
546
- # ############################## end of file ############################# #
547
550
 
551
+ # ############################## end of file ############################# #
548
552