libclimate-ruby 0.6.2 → 0.7.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ca1b0b3762f52fff8e5bd7d819cace47cc2a525c
4
- data.tar.gz: 1eba780dd077d680573355accb035e7b016a83a1
3
+ metadata.gz: 508db783549ec969fcfaca95ac11cebcbc29a340
4
+ data.tar.gz: 4cb1d7eb161c1992e94500daded0068a6b018f41
5
5
  SHA512:
6
- metadata.gz: d52935c271d5e5ac6fb6a703962d353f5435e1f3c968bf018c40781eb7999351fdb0f1c74f2f53d7117cb482ffc1e1d2e3e5f50e97cdc944fe381877629932ec
7
- data.tar.gz: 4ac5853b341fa530eb67536889b174bd05177b2bee3ea84e01f5558d5a369a24bec3505c7f235cb333467a81b4bc7ea5dc97ecb7d83523dca2256375d34b06cb
6
+ metadata.gz: beffffe172884c20114e2cb3d705e504f555980393f33ddc246eed5966714b645d0bed9e6a08d6cba6b592782ab215865cfd6178a9a332bfe08364e4d1334df8
7
+ data.tar.gz: e4a0c48f13a41c88ea2feb1a0b213e31e23dfdb69a503715820eea8d6b835f1352cf0a1aa5909daf632985487f509145940b64201ce9a2601a38c63f54fc63ea
@@ -5,13 +5,13 @@
5
5
  # Purpose: Definition of the ::LibCLImate::Climate class
6
6
  #
7
7
  # Created: 13th July 2015
8
- # Updated: 16th March 2017
8
+ # Updated: 1st January 2018
9
9
  #
10
10
  # Home: http://github.com/synesissoftware/libCLImate.Ruby
11
11
  #
12
12
  # Author: Matthew Wilson
13
13
  #
14
- # Copyright (c) 2015-2017, Matthew Wilson and Synesis Software
14
+ # Copyright (c) 2015-2018, 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
@@ -44,6 +44,9 @@ require 'clasp'
44
44
  require 'xqsr3/extensions/io'
45
45
  require 'xqsr3/quality/parameter_checking'
46
46
 
47
+ =begin
48
+ =end
49
+
47
50
  if !defined? Colcon
48
51
 
49
52
  begin
@@ -128,10 +131,35 @@ module LibCLImate
128
131
 
129
132
  # Class used to gather together the CLI specification, and execute it
130
133
  #
134
+ # The standard usage pattern is as follows:
135
+ #
136
+ # PROGRAM_VERSION = [ 0, 1, 2 ]
137
+ #
138
+ # program_options = {}
139
+ #
140
+ # climate = LibCLImate::Climate.new do |cl|
141
+ #
142
+ # cl.add_flag('--verbose', alias: '-v', help: 'Makes program output verbose') { program_options[:verbose] = true }
143
+ #
144
+ # cl.add_option('--flavour', alias: '-f', help: 'Specifies the flavour') do |o, a|
145
+ #
146
+ # program_options[:flavour] = check_flavour(o.value) or cl.abort "Invalid flavour '#{o.value}'; use --help for usage"
147
+ # end
148
+ #
149
+ # cl.usage_value = '<value-1> [ ... <value-N> ]'
131
150
  #
151
+ # cl.info_lines = [
152
+ #
153
+ # 'ACME CLI program (using libCLImate)',
154
+ # :version,
155
+ # 'An example program',
156
+ # ]
157
+ # end
132
158
  #
133
159
  class Climate
134
160
 
161
+ include ::Xqsr3::Quality::ParameterChecking
162
+
135
163
  #:stopdoc:
136
164
 
137
165
  private
@@ -147,9 +175,51 @@ class Climate
147
175
 
148
176
  def show_version_
149
177
 
150
- ver = version || []
178
+ CLASP.show_version aliases, stream: stdout, program_name: program_name, version: version, exit: exit_on_usage ? 0 : nil
179
+ end
180
+
181
+ def infer_version_ ctxt
182
+
183
+ # algorithm:
184
+ #
185
+ # 1. PROGRAM_VERSION: loaded from ctxt / global
186
+ # 2. PROGRAM_VER(SION)_(MAJOR|MINOR|REVISION|BUILD): loaded from
187
+ # ctxt / global
188
+
189
+ if ctxt
190
+
191
+ ctxt = ctxt.class unless ::Class === ctxt
192
+
193
+ return ctxt.const_get(:PROGRAM_VERSION) if ctxt.const_defined? :PROGRAM_VERSION
194
+
195
+ ver = []
196
+
197
+ if ctxt.const_defined? :PROGRAM_VER_MAJOR
198
+
199
+ ver << ctxt.const_get(:PROGRAM_VER_MAJOR)
200
+
201
+ if ctxt.const_defined? :PROGRAM_VER_MINOR
202
+
203
+ ver << ctxt.const_get(:PROGRAM_VER_MINOR)
204
+
205
+ if ctxt.const_defined? :PROGRAM_VER_REVISION
206
+
207
+ ver << ctxt.const_get(:PROGRAM_VER_REVISION)
208
+
209
+ if ctxt.const_defined? :PROGRAM_VER_BUILD
210
+
211
+ ver << ctxt.const_get(:PROGRAM_VER_BUILD)
212
+ end
213
+ end
214
+ end
215
+
216
+ return ver
217
+ end
218
+ else
151
219
 
152
- if ver.empty?
220
+ return PROGRAM_VERSION if defined? PROGRAM_VERSION
221
+
222
+ ver = []
153
223
 
154
224
  if defined? PROGRAM_VER_MAJOR
155
225
 
@@ -162,14 +232,20 @@ class Climate
162
232
  if defined? PROGRAM_VER_REVISION
163
233
 
164
234
  ver << PROGRAM_VER_REVISION
235
+
236
+ if defined? PROGRAM_VER_BUILD
237
+
238
+ ver << PROGRAM_VER_BUILD
239
+ end
165
240
  end
166
241
  end
242
+
243
+ return ver
167
244
  end
168
245
  end
169
246
 
170
- CLASP.show_version aliases, stream: stdout, program_name: program_name, version: version, exit: exit_on_usage ? 0 : nil
247
+ nil
171
248
  end
172
-
173
249
  #:startdoc:
174
250
 
175
251
  public
@@ -184,6 +260,8 @@ class Climate
184
260
  # * *Options*:
185
261
  # - +:no_help_flag+:: Prevents the use of the CLASP::Flag.Help flag-alias
186
262
  # - +:no_version_flag+:: Prevents the use of the CLASP::Version.Help flag-alias
263
+ # - +:version+:: A version specification. If not specified, this is
264
+ # inferred
187
265
  #
188
266
  # * *Block*:: An optional block which receives the constructing instance, allowing the user to modify the attributes.
189
267
  def initialize(options={}) # :yields: climate
@@ -200,13 +278,15 @@ class Climate
200
278
 
201
279
  @aliases = []
202
280
  @exit_on_unknown = true
281
+ @exit_on_missing = true
203
282
  @exit_on_usage = true
204
283
  @info_lines = nil
205
284
  @program_name = program_name
206
285
  @stdout = $stdout
207
286
  @stderr = $stderr
208
287
  @usage_values = usage_values
209
- @version = []
288
+ version_context = options[:version_context]
289
+ @version = options[:version] || infer_version_(version_context)
210
290
 
211
291
  @aliases << CLASP::Flag.Help(handle: proc { show_usage_ }) unless options[:no_help_flag]
212
292
  @aliases << CLASP::Flag.Version(handle: proc { show_version_ }) unless options[:no_version_flag]
@@ -217,6 +297,12 @@ class Climate
217
297
  # An array of aliases attached to the climate instance, whose contents should be modified by adding (or removing) CLASP aliases
218
298
  # @return [Array] The aliases
219
299
  attr_reader :aliases
300
+ # Indicates whether exit will be called (with non-zero exit code) when a
301
+ # required command-line option is missing
302
+ # @return [Boolean]
303
+ # @return *true* exit(1) will be called
304
+ # @return *false* exit will not be called
305
+ attr_accessor :exit_on_missing
220
306
  # Indicates whether exit will be called (with non-zero exit code) when an unknown command-line flag or option is encountered
221
307
  # @return [Boolean]
222
308
  # @return *true* exit(1) will be called
@@ -234,7 +320,7 @@ class Climate
234
320
  attr_accessor :stderr
235
321
  # @return [String] Optional string to describe the program values, eg \<xyz "[ { <<directory> | &lt;file> } ]"
236
322
  attr_accessor :usage_values
237
- # @return [String, Array] A version string or an array of integers representing the version components
323
+ # @return [String, Array] A version string or an array of integers representing the version component(s)
238
324
  attr_accessor :version
239
325
 
240
326
  # Executes the prepared Climate instance
@@ -264,7 +350,7 @@ class Climate
264
350
  given: flags,
265
351
  handled: [],
266
352
  unhandled: [],
267
- unknown: []
353
+ unknown: [],
268
354
  },
269
355
 
270
356
  options: {
@@ -272,10 +358,12 @@ class Climate
272
358
  given: options,
273
359
  handled: [],
274
360
  unhandled: [],
275
- unknown: []
361
+ unknown: [],
276
362
  },
277
363
 
278
- values: values
364
+ values: values,
365
+
366
+ missing_option_aliases: [],
279
367
  }
280
368
 
281
369
  flags.each do |f|
@@ -289,7 +377,7 @@ class Climate
289
377
 
290
378
  selector = :unhandled
291
379
 
292
- # see if it has a :action attribute (which will have been
380
+ # see if it has an :action attribute (which will have been
293
381
  # monkey-patched to CLASP.Flag()
294
382
 
295
383
  if al.respond_to?(:action) && !al.action.nil?
@@ -346,7 +434,7 @@ class Climate
346
434
 
347
435
  selector = :unhandled
348
436
 
349
- # see if it has a :action attribute (which will have been
437
+ # see if it has an :action attribute (which will have been
350
438
  # monkey-patched to CLASP.Option()
351
439
 
352
440
  if al.respond_to?(:action) && !al.action.nil?
@@ -392,6 +480,41 @@ class Climate
392
480
  end
393
481
  end
394
482
 
483
+
484
+ # now police any required options
485
+
486
+ required_aliases = aliases.select do |a|
487
+
488
+ a.kind_of?(::CLASP::Option) && a.required?
489
+ end
490
+
491
+ required_aliases = Hash[required_aliases.map { |a| [ a.name, a ] }]
492
+
493
+ given_options = Hash[results[:options][:given].map { |o| [ o.name, o ]}]
494
+
495
+ required_aliases.each do |k, a|
496
+
497
+ unless given_options.has_key? k
498
+
499
+ message = a.required_message
500
+
501
+ if exit_on_missing
502
+
503
+ self.abort message
504
+ else
505
+
506
+ if program_name && !program_name.empty?
507
+
508
+ message = "#{program_name}: #{message}"
509
+ end
510
+
511
+ stderr.puts message
512
+ end
513
+
514
+ results[:missing_option_aliases] << a
515
+ end
516
+ end
517
+
395
518
  def results.flags
396
519
 
397
520
  self[:flags]
@@ -473,7 +596,7 @@ class Climate
473
596
  # - +:extras+::
474
597
  def add_flag(name, options={}, &block)
475
598
 
476
- ::Xqsr3::Quality::ParameterChecking.check_parameter name, 'name', allow_nil: false, types: [ ::String, ::Symbol ]
599
+ check_parameter name, 'name', allow_nil: false, types: [ ::String, ::Symbol ]
477
600
 
478
601
  aliases << CLASP.Flag(name, **options, &block)
479
602
  end
@@ -488,7 +611,7 @@ class Climate
488
611
  # - +:extras+::
489
612
  def add_option(name, options={}, &block)
490
613
 
491
- ::Xqsr3::Quality::ParameterChecking.check_parameter name, 'name', allow_nil: false, types: [ ::String, ::Symbol ]
614
+ check_parameter name, 'name', allow_nil: false, types: [ ::String, ::Symbol ]
492
615
 
493
616
  aliases << CLASP.Option(name, **options, &block)
494
617
  end
@@ -533,7 +656,7 @@ class Climate
533
656
  # +climate.add_alias('--verbosity=verbose', '-v')+
534
657
  def add_alias(name, *aliases)
535
658
 
536
- ::Xqsr3::Quality::ParameterChecking.check_parameter name, 'name', allow_nil: false, types: [ ::String, ::Symbol ]
659
+ check_parameter name, 'name', allow_nil: false, types: [ ::String, ::Symbol ]
537
660
  raise ArgumentError, "must supply at least one alias" if aliases.empty?
538
661
 
539
662
  self.aliases << CLASP.Option(name, aliases: aliases)
@@ -4,11 +4,11 @@
4
4
  # Purpose: Main file for libclimate.Ruby library
5
5
  #
6
6
  # Created: 13th July 2015
7
- # Updated: 12th June 2016
7
+ # Updated: 9th June 2017
8
8
  #
9
9
  # Home: http://github.com/synesissoftware/libCLImate.Ruby
10
10
  #
11
- # Copyright (c) 2015-2016, Matthew Wilson and Synesis Software
11
+ # Copyright (c) 2015-2017, Matthew Wilson and Synesis Software
12
12
  # All rights reserved.
13
13
  #
14
14
  # Redistribution and use in source and binary forms, with or without
@@ -40,6 +40,9 @@
40
40
  require 'libclimate/climate'
41
41
  require 'libclimate/version'
42
42
 
43
+ =begin
44
+ =end
45
+
43
46
  # Main module for libCLImate.Ruby library
44
47
  module LibCLImate
45
48
 
@@ -4,11 +4,11 @@
4
4
  # Purpose: Version for libclimate.Ruby library
5
5
  #
6
6
  # Created: 13th July 2015
7
- # Updated: 5th July 2016
7
+ # Updated: 3rd January 2018
8
8
  #
9
9
  # Home: http://github.com/synesissoftware/libCLImate.Ruby
10
10
  #
11
- # Copyright (c) 2015-2016, Matthew Wilson and Synesis Software
11
+ # Copyright (c) 2015-2018, Matthew Wilson and Synesis Software
12
12
  # All rights reserved.
13
13
  #
14
14
  # Redistribution and use in source and binary forms, with or without
@@ -37,10 +37,13 @@
37
37
  # ######################################################################## #
38
38
 
39
39
 
40
+ =begin
41
+ =end
42
+
40
43
  module LibCLImate
41
44
 
42
45
  # Current version of the libCLImate.Ruby library
43
- VERSION = '0.6.2'
46
+ VERSION = '0.7.2'
44
47
 
45
48
  private
46
49
  VERSION_PARTS_ = VERSION.split(/[.]/).collect { |n| n.to_i } # :nodoc:
@@ -3,10 +3,10 @@
3
3
  #############################################################################
4
4
  # File: test/scratch/blankzeroes.rb
5
5
  #
6
- # Purpose: COMPLETE_ME
6
+ # Purpose: This filter program converts 0 values in a TSV into blanks
7
7
  #
8
- # Created: 14 05 2016
9
- # Updated: 14 05 2016
8
+ # Created: 14th May 2016
9
+ # Updated: 1st January 2018
10
10
  #
11
11
  # Author: Matthew Wilson
12
12
  #
@@ -24,14 +24,19 @@ require 'libclimate'
24
24
 
25
25
  PROGRAM_VER_MAJOR = 0
26
26
  PROGRAM_VER_MINOR = 1
27
- PROGRAM_VER_REVISION = 2
27
+ PROGRAM_VER_REVISION = 3
28
+ PROGRAM_VER_BUILD = 5
28
29
 
29
30
  # ##########################################################
30
31
  # command-line parsing
31
32
 
32
- LibCLImate::Climate.new do |climate|
33
+ LibCLImate::Climate.new do |cl|
33
34
 
34
- climate.version = [ PROGRAM_VER_MAJOR, PROGRAM_VER_MINOR, PROGRAM_VER_REVISION ]
35
+ cl.info_lines = [
36
+
37
+ :version,
38
+ 'converts 0 values into blanks',
39
+ ]
35
40
  end.run
36
41
 
37
42
  # ##########################################################
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
-
3
2
  #
3
+ # test version inference
4
4
 
5
5
  $:.unshift File.join(File.dirname(__FILE__), '../..', 'lib')
6
6
 
@@ -23,19 +23,21 @@ class Test_Climate_infer_version_3_22 < Test::Unit::TestCase
23
23
 
24
24
  strout = StringIO.new
25
25
 
26
- climate = LibCLImate::Climate.new do |climate|
26
+ climate = LibCLImate::Climate.new(version_context: self) do |cl|
27
+
28
+ cl.program_name = 'myprog'
29
+ cl.stdout = strout
27
30
 
28
- climate.program_name = 'myprog'
29
- climate.stdout = strout
31
+ cl.exit_on_usage = false
30
32
  end.run [ 'myprog', '--version' ]
31
33
 
32
34
  s = strout.string
33
35
 
34
- assert_equal "myprog 3.22", s
36
+ assert_equal "myprog 3.22", s.chomp
35
37
  end
36
38
  end
37
39
 
38
- class Test_Climate_infer_version_3_2 < Test::Unit::TestCase
40
+ class Test_Climate_infer_version_3_2_99 < Test::Unit::TestCase
39
41
 
40
42
  PROGRAM_VER_MINOR = 2
41
43
  PROGRAM_VER_REVISION = 99
@@ -44,15 +46,39 @@ class Test_Climate_infer_version_3_2 < Test::Unit::TestCase
44
46
 
45
47
  strout = StringIO.new
46
48
 
47
- climate = LibCLImate::Climate.new do |climate|
49
+ climate = LibCLImate::Climate.new(version_context: self) do |cl|
50
+
51
+ cl.program_name = 'myprog'
52
+ cl.stdout = strout
53
+
54
+ cl.exit_on_usage = false
55
+ end.run [ 'myprog', '--version' ]
56
+
57
+ s = strout.string
58
+
59
+ assert_equal "myprog 3.2.99", s.chomp
60
+ end
61
+ end
62
+
63
+ class Test_Climate_infer_PROGRAM_VERSION_as_array < Test::Unit::TestCase
64
+
65
+ PROGRAM_VERSION = [ 11, 12, 13 ]
66
+
67
+ def test_inference_of_version
68
+
69
+ strout = StringIO.new
70
+
71
+ climate = LibCLImate::Climate.new(version_context: self) do |cl|
72
+
73
+ cl.program_name = 'myprog'
74
+ cl.stdout = strout
48
75
 
49
- climate.program_name = 'myprog'
50
- climate.stdout = strout
76
+ cl.exit_on_usage = false
51
77
  end.run [ 'myprog', '--version' ]
52
78
 
53
79
  s = strout.string
54
80
 
55
- assert_equal "myprog 3.2.99", s
81
+ assert_equal "myprog 11.12.13", s.chomp
56
82
  end
57
83
  end
58
84
 
@@ -55,7 +55,7 @@ class Test_Climate_minimal < Test::Unit::TestCase
55
55
 
56
56
  assert_not_nil r
57
57
  assert_kind_of ::Hash, r
58
- assert_equal 3, r.size
58
+ assert 3 <= r.size
59
59
  assert_not_nil r[:flags]
60
60
  assert_not_nil r[:options]
61
61
  assert_not_nil r[:values]
@@ -103,7 +103,7 @@ class Test_Climate_minimal < Test::Unit::TestCase
103
103
 
104
104
  assert_not_nil r
105
105
  assert_kind_of ::Hash, r
106
- assert_equal 3, r.size
106
+ assert 3 <= r.size
107
107
  assert_not_nil r[:flags]
108
108
  assert_not_nil r[:options]
109
109
  assert_not_nil r[:values]
@@ -233,7 +233,7 @@ class Test_Climate_minimal < Test::Unit::TestCase
233
233
 
234
234
  assert_not_nil r
235
235
  assert_kind_of ::Hash, r
236
- assert_equal 3, r.size
236
+ assert 3 <= r.size
237
237
  assert argv.equal? r.argv
238
238
  assert_not_nil r[:flags]
239
239
  assert_not_nil r[:options]
@@ -291,7 +291,7 @@ class Test_Climate_minimal < Test::Unit::TestCase
291
291
 
292
292
  assert_not_nil r
293
293
  assert_kind_of ::Hash, r
294
- assert_equal 3, r.size
294
+ assert 3 <= r.size
295
295
  assert argv.equal? r.argv
296
296
  assert_not_nil r[:flags]
297
297
  assert_not_nil r[:options]
@@ -336,7 +336,7 @@ class Test_Climate_minimal < Test::Unit::TestCase
336
336
 
337
337
  assert_not_nil r
338
338
  assert_kind_of ::Hash, r
339
- assert_equal 3, r.size
339
+ assert 3 <= r.size
340
340
  assert argv.equal? r.argv
341
341
  assert_not_nil r[:flags]
342
342
  assert_not_nil r[:options]
@@ -359,7 +359,198 @@ class Test_Climate_minimal < Test::Unit::TestCase
359
359
  assert_equal 0, lines.size
360
360
  assert_equal '2', verbosity
361
361
  end
362
+
363
+ def test_one_custom_option_that_is_required
364
+
365
+ str = StringIO.new
366
+
367
+ climate = LibCLImate::Climate.new do |climate|
368
+
369
+ climate.program_name = 'program'
370
+
371
+ climate.add_option('--verbosity', alias: '-v', help: 'determines level of verbose operation', required: true)
372
+ end
373
+
374
+ assert climate.aliases[2].required?
375
+
376
+ r = climate.run %w{ -v 2 }
377
+
378
+ assert_not_nil r
379
+ assert_kind_of ::Hash, r
380
+ assert 3 <= r.size
381
+ assert_not_nil r[:flags]
382
+ assert_not_nil r[:options]
383
+ assert_not_nil r[:values]
384
+ assert_equal 4, r[:flags].size
385
+ assert_equal 0, r[:flags][:given].size
386
+ assert_equal 0, r[:flags][:handled].size
387
+ assert_equal 0, r[:flags][:unhandled].size
388
+ assert_equal 0, r[:flags][:unknown].size
389
+ assert_equal 4, r[:options].size
390
+ assert_equal 1, r[:options][:given].size
391
+ assert_equal 0, r[:options][:handled].size
392
+ assert_equal 1, r[:options][:unhandled].size
393
+ assert_equal 0, r[:options][:unknown].size
394
+ assert_equal 0, r[:values].size
395
+ assert_equal 0, r[:missing_option_aliases].size
396
+ lines = str.string.split(/\n/)
397
+ lines = lines.reject { |line| line.chomp.strip.empty? }
398
+ lines = lines.map { |line| line.chomp.strip }
399
+
400
+ assert_equal 0, lines.size
401
+ end
402
+
403
+ def test_one_custom_option_that_is_required_and_missing
404
+
405
+ str = StringIO.new
406
+ stre = StringIO.new
407
+
408
+ climate = LibCLImate::Climate.new do |climate|
409
+
410
+ climate.program_name = 'program'
411
+ climate.stdout = str
412
+ climate.stderr = stre
413
+ climate.exit_on_usage = false
414
+ climate.exit_on_missing = false
415
+
416
+ climate.add_option('--verbosity', alias: '-v', help: 'determines level of verbose operation', required: true)
417
+ end
418
+
419
+ r = climate.run %w{ }
420
+
421
+ assert climate.aliases[2].required?
422
+
423
+ assert_not_nil r
424
+ assert_kind_of ::Hash, r
425
+ assert 3 <= r.size
426
+ assert_not_nil r[:flags]
427
+ assert_not_nil r[:options]
428
+ assert_not_nil r[:values]
429
+ assert_equal 4, r[:flags].size
430
+ assert_equal 0, r[:flags][:given].size
431
+ assert_equal 0, r[:flags][:handled].size
432
+ assert_equal 0, r[:flags][:unhandled].size
433
+ assert_equal 0, r[:flags][:unknown].size
434
+ assert_equal 4, r[:options].size
435
+ assert_equal 0, r[:options][:given].size
436
+ assert_equal 0, r[:options][:handled].size
437
+ assert_equal 0, r[:options][:unhandled].size
438
+ assert_equal 0, r[:options][:unknown].size
439
+ assert_equal 0, r[:values].size
440
+ assert_equal 1, r[:missing_option_aliases].size
441
+ lines = str.string.split(/\n/)
442
+ lines = lines.reject { |line| line.chomp.strip.empty? }
443
+ lines = lines.map { |line| line.chomp.strip }
444
+ elines = stre.string.split(/\n/)
445
+ elines = elines.reject { |line| line.chomp.strip.empty? }
446
+ elines = elines.map { |line| line.chomp.strip }
447
+
448
+ assert_equal 0, lines.size
449
+ assert_equal 1, elines.size
450
+ assert_equal "program: '--verbosity' not specified; use --help for usage", elines[0]
451
+ end
452
+
453
+ def test_one_custom_option_that_is_required_and_missing_with_required_message_custom
454
+
455
+ str = StringIO.new
456
+ stre = StringIO.new
457
+
458
+ climate = LibCLImate::Climate.new do |climate|
459
+
460
+ climate.program_name = 'program'
461
+ climate.stdout = str
462
+ climate.stderr = stre
463
+ climate.exit_on_usage = false
464
+ climate.exit_on_missing = false
465
+
466
+ climate.add_option('--verbosity', alias: '-v', help: 'determines level of verbose operation', required: true, required_message: 'Verbosity not specified')
467
+ end
468
+
469
+ r = climate.run %w{ }
470
+
471
+ assert climate.aliases[2].required?
472
+
473
+ assert_not_nil r
474
+ assert_kind_of ::Hash, r
475
+ assert 3 <= r.size
476
+ assert_not_nil r[:flags]
477
+ assert_not_nil r[:options]
478
+ assert_not_nil r[:values]
479
+ assert_equal 4, r[:flags].size
480
+ assert_equal 0, r[:flags][:given].size
481
+ assert_equal 0, r[:flags][:handled].size
482
+ assert_equal 0, r[:flags][:unhandled].size
483
+ assert_equal 0, r[:flags][:unknown].size
484
+ assert_equal 4, r[:options].size
485
+ assert_equal 0, r[:options][:given].size
486
+ assert_equal 0, r[:options][:handled].size
487
+ assert_equal 0, r[:options][:unhandled].size
488
+ assert_equal 0, r[:options][:unknown].size
489
+ assert_equal 0, r[:values].size
490
+ assert_equal 1, r[:missing_option_aliases].size
491
+ lines = str.string.split(/\n/)
492
+ lines = lines.reject { |line| line.chomp.strip.empty? }
493
+ lines = lines.map { |line| line.chomp.strip }
494
+ elines = stre.string.split(/\n/)
495
+ elines = elines.reject { |line| line.chomp.strip.empty? }
496
+ elines = elines.map { |line| line.chomp.strip }
497
+
498
+ assert_equal 0, lines.size
499
+ assert_equal 1, elines.size
500
+ assert_equal "program: Verbosity not specified", elines[0]
501
+ end
502
+
503
+ def test_one_custom_option_that_is_required_and_missing_with_required_message_name
504
+
505
+ str = StringIO.new
506
+ stre = StringIO.new
507
+
508
+ climate = LibCLImate::Climate.new do |climate|
509
+
510
+ climate.program_name = 'program'
511
+ climate.stdout = str
512
+ climate.stderr = stre
513
+ climate.exit_on_usage = false
514
+ climate.exit_on_missing = false
515
+
516
+ climate.add_option('--verbosity', alias: '-v', help: 'determines level of verbose operation', required: true, required_message: "\0Verbosity")
517
+ end
518
+
519
+ r = climate.run %w{ }
520
+
521
+ assert climate.aliases[2].required?
522
+
523
+ assert_not_nil r
524
+ assert_kind_of ::Hash, r
525
+ assert 3 <= r.size
526
+ assert_not_nil r[:flags]
527
+ assert_not_nil r[:options]
528
+ assert_not_nil r[:values]
529
+ assert_equal 4, r[:flags].size
530
+ assert_equal 0, r[:flags][:given].size
531
+ assert_equal 0, r[:flags][:handled].size
532
+ assert_equal 0, r[:flags][:unhandled].size
533
+ assert_equal 0, r[:flags][:unknown].size
534
+ assert_equal 4, r[:options].size
535
+ assert_equal 0, r[:options][:given].size
536
+ assert_equal 0, r[:options][:handled].size
537
+ assert_equal 0, r[:options][:unhandled].size
538
+ assert_equal 0, r[:options][:unknown].size
539
+ assert_equal 0, r[:values].size
540
+ assert_equal 1, r[:missing_option_aliases].size
541
+ lines = str.string.split(/\n/)
542
+ lines = lines.reject { |line| line.chomp.strip.empty? }
543
+ lines = lines.map { |line| line.chomp.strip }
544
+ elines = stre.string.split(/\n/)
545
+ elines = elines.reject { |line| line.chomp.strip.empty? }
546
+ elines = elines.map { |line| line.chomp.strip }
547
+
548
+ assert_equal 0, lines.size
549
+ assert_equal 1, elines.size
550
+ assert_equal "program: Verbosity not specified; use --help for usage", elines[0]
551
+ end
362
552
  end
363
553
 
364
554
  # ############################## end of file ############################# #
365
555
 
556
+
@@ -55,7 +55,7 @@ class Test_Climate_minimal_CLASP < Test::Unit::TestCase
55
55
 
56
56
  assert_not_nil r
57
57
  assert_kind_of ::Hash, r
58
- assert_equal 3, r.size
58
+ assert 3 <= r.size
59
59
  assert_not_nil r[:flags]
60
60
  assert_not_nil r[:options]
61
61
  assert_not_nil r[:values]
@@ -103,7 +103,7 @@ class Test_Climate_minimal_CLASP < Test::Unit::TestCase
103
103
 
104
104
  assert_not_nil r
105
105
  assert_kind_of ::Hash, r
106
- assert_equal 3, r.size
106
+ assert 3 <= r.size
107
107
  assert_not_nil r[:flags]
108
108
  assert_not_nil r[:options]
109
109
  assert_not_nil r[:values]
@@ -233,7 +233,7 @@ class Test_Climate_minimal_CLASP < Test::Unit::TestCase
233
233
 
234
234
  assert_not_nil r
235
235
  assert_kind_of ::Hash, r
236
- assert_equal 3, r.size
236
+ assert 3 <= r.size
237
237
  assert_not_nil r[:flags]
238
238
  assert_not_nil r[:options]
239
239
  assert_not_nil r[:values]
@@ -290,7 +290,7 @@ class Test_Climate_minimal_CLASP < Test::Unit::TestCase
290
290
 
291
291
  assert_not_nil r
292
292
  assert_kind_of ::Hash, r
293
- assert_equal 3, r.size
293
+ assert 3 <= r.size
294
294
  assert_not_nil r[:flags]
295
295
  assert_not_nil r[:options]
296
296
  assert_not_nil r[:values]
@@ -334,7 +334,7 @@ class Test_Climate_minimal_CLASP < Test::Unit::TestCase
334
334
 
335
335
  assert_not_nil r
336
336
  assert_kind_of ::Hash, r
337
- assert_equal 3, r.size
337
+ assert 3 <= r.size
338
338
  assert_not_nil r[:flags]
339
339
  assert_not_nil r[:options]
340
340
  assert_not_nil r[:values]
@@ -36,7 +36,7 @@ class Test_Climate_minimal < Test::Unit::TestCase
36
36
 
37
37
  assert_not_nil r
38
38
  assert_kind_of ::Hash, r
39
- assert_equal 3, r.size
39
+ assert 3 <= r.size
40
40
  assert_equal 0, r.flags[:given].size
41
41
 
42
42
  assert_equal 1, options.size
data/test/unit/ts_all.rb CHANGED
@@ -2,7 +2,6 @@
2
2
  #
3
3
  # executes all other tests
4
4
 
5
- this_file = File.expand_path(__FILE__)
6
5
  this_dir = File.expand_path(File.dirname(__FILE__))
7
6
 
8
7
  # all tc_*rb in current directory
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libclimate-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Wilson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-16 00:00:00.000000000 Z
11
+ date: 2018-01-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clasp-ruby
@@ -16,7 +16,7 @@ dependencies:
16
16
  requirements:
17
17
  - - '>='
18
18
  - !ruby/object:Gem::Version
19
- version: 0.10.2
19
+ version: 0.12.1
20
20
  - - <
21
21
  - !ruby/object:Gem::Version
22
22
  version: '1.0'
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - '>='
28
28
  - !ruby/object:Gem::Version
29
- version: 0.10.2
29
+ version: 0.12.1
30
30
  - - <
31
31
  - !ruby/object:Gem::Version
32
32
  version: '1.0'