libclimate-ruby 0.3.1 → 0.4.1

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: 8ddeb7a8f3fbcbe387ff00dc9c0413a2921a1573
4
- data.tar.gz: 205642b3c90c1c34685163a87534b496e10b1e97
3
+ metadata.gz: d55c53e5b2ddc3f8726d800b40b4d3b314abf8c5
4
+ data.tar.gz: 8846d76a971949a876c3ef83c6c022d41e6435d6
5
5
  SHA512:
6
- metadata.gz: 9fa38dafe06b342668e826492f9219904833f1e0a91feb11754f8731187bf42106fcad467ec08c7b8d360fb6ddeb4c9cf68c1bd63ba69aa54a206126a79c1a79
7
- data.tar.gz: 3c8de16fba64582e4d4fc9ec9bf121c924de7b3a736972c413f2e28b86c47446bd9154daed06658e5d303e6c3f4c1946e66b57aebad730fac5e3809766d130cf
6
+ metadata.gz: 56e9b36042061363132ed2a8464c965947b472a484a4fb3831e482b7ae64bc9de4833713cd624fbea76744eff4001840334fe4b3735806526e6dc22cc76c451d
7
+ data.tar.gz: 5ea0e2a5fa012615cb101d77047ac2c373e3fa96e395e7b45000f58f00cec22ce0ddc695095c15ada8774daedfc61d61211adb0256464dde0d2b3aac959480ec
@@ -5,7 +5,7 @@
5
5
  # Purpose: Definition of the ::LibCLImate::Climate class
6
6
  #
7
7
  # Created: 13th July 2015
8
- # Updated: 13th June 2016
8
+ # Updated: 14th June 2016
9
9
  #
10
10
  # Home: http://github.com/synesissoftware/libCLImate.Ruby
11
11
  #
@@ -217,6 +217,14 @@ class Climate
217
217
  attr_accessor :version
218
218
 
219
219
  # Executes the prepared Climate instance
220
+ #
221
+ # == Signature
222
+ #
223
+ # * *Parameters*:
224
+ # - +argv+:: The array of arguments; defaults to <tt>ARGV</tt>
225
+ #
226
+ # * *Returns*:
227
+ #
220
228
  def run argv = ARGV
221
229
 
222
230
  raise ArgumentError, "argv may not be nil" if argv.nil?
@@ -318,6 +326,7 @@ class Climate
318
326
 
319
327
  selector = :handled
320
328
  else
329
+
321
330
  ex = al.extras
322
331
 
323
332
  case ex
@@ -365,6 +374,49 @@ class Climate
365
374
 
366
375
  results
367
376
  end
377
+
378
+ # Calls abort() with the given message prefixed by the program_name
379
+ #
380
+ # === Signature
381
+ #
382
+ # * *Parameters*:
383
+ # - +message+:: The message string
384
+ # - +options+:: An option hash, containing any of the following options
385
+ #
386
+ # * *Options*:
387
+ # - +:stream+:: {optional} The output stream to use. Defaults to the value of the attribute +stderr+.
388
+ # - +:program_name+:: {optional} Uses the given value rather than the +program_name+ attribute; does not prefix if the empty string
389
+ # - +:exit+:: {optional} The exit code. Defaults to 1. Does not exit if +nil+ specified.
390
+ #
391
+ # * *Return*:
392
+ # The combined message string, if <tt>exit()</tt> not called.
393
+ def abort message, options={}
394
+
395
+ prog_name = options[:program_name]
396
+ prog_name ||= program_name
397
+ prog_name ||= ''
398
+
399
+ stream = options[:stream]
400
+ stream ||= stderr
401
+ stream ||= $stderr
402
+
403
+ exit_code = options.has_key?(:exit) ? options[:exit] : 1
404
+
405
+ if prog_name.empty?
406
+
407
+ msg = message
408
+ else
409
+
410
+ msg = "#{prog_name}: #{message}"
411
+ end
412
+
413
+
414
+ stream.puts msg
415
+
416
+ exit(exit_code) if exit_code
417
+
418
+ msg
419
+ end
368
420
  end # class Climate
369
421
 
370
422
  end # module LibCLImate
@@ -4,7 +4,7 @@
4
4
  # Purpose: Version for libclimate.Ruby library
5
5
  #
6
6
  # Created: 13th July 2015
7
- # Updated: 13th June 2016
7
+ # Updated: 14th June 2016
8
8
  #
9
9
  # Home: http://github.com/synesissoftware/libCLImate.Ruby
10
10
  #
@@ -40,7 +40,7 @@
40
40
  module LibCLImate
41
41
 
42
42
  # Current version of the libCLImate.Ruby library
43
- VERSION = '0.3.1'
43
+ VERSION = '0.4.1'
44
44
 
45
45
  private
46
46
  VERSION_PARTS_ = VERSION.split(/[.]/).collect { |n| n.to_i } # :nodoc:
@@ -0,0 +1,87 @@
1
+ #!/usr/bin/ruby
2
+ #
3
+ # test abort
4
+
5
+ $:.unshift File.join(File.dirname(__FILE__), '../..', 'lib')
6
+
7
+
8
+ require 'libclimate'
9
+
10
+ require 'xqsr3/extensions/test/unit'
11
+
12
+ require 'test/unit'
13
+
14
+ require 'stringio'
15
+
16
+ class Test_Climate_abort < Test::Unit::TestCase
17
+
18
+ def test_abort_normal
19
+
20
+ strout = StringIO.new
21
+ strerr = StringIO.new
22
+
23
+ climate = LibCLImate::Climate.new do |climate|
24
+
25
+ climate.program_name = 'myprog'
26
+ climate.stdout = strout
27
+ climate.stderr = strerr
28
+ end
29
+
30
+ s = climate.abort 'something happened', exit: nil
31
+
32
+ lines_err = strerr.string.split /\n/
33
+
34
+ assert_equal 'myprog: something happened', s
35
+
36
+ assert_equal 1, lines_err.size
37
+ assert_equal 'myprog: something happened', lines_err[0]
38
+ end
39
+
40
+ def test_abort_no_program_name
41
+
42
+ strout = StringIO.new
43
+ strerr = StringIO.new
44
+
45
+ climate = LibCLImate::Climate.new do |climate|
46
+
47
+ climate.program_name = 'myprog'
48
+ climate.stdout = strout
49
+ climate.stderr = strerr
50
+ end
51
+
52
+ s = climate.abort 'something happened', exit: nil, program_name: ''
53
+
54
+ lines_err = strerr.string.split /\n/
55
+
56
+ assert_equal 'something happened', s
57
+
58
+ assert_equal 1, lines_err.size
59
+ assert_equal 'something happened', lines_err[0]
60
+ end
61
+
62
+ def test_abort_custom_program_name
63
+
64
+ strout = StringIO.new
65
+ strerr = StringIO.new
66
+
67
+ climate = LibCLImate::Climate.new do |climate|
68
+
69
+ climate.program_name = 'myprog'
70
+ climate.stdout = strout
71
+ climate.stderr = strerr
72
+ end
73
+
74
+ s = climate.abort 'something happened', exit: nil, program_name: 'my-prog'
75
+
76
+ lines_err = strerr.string.split /\n/
77
+
78
+ assert_equal 'my-prog: something happened', s
79
+
80
+ assert_equal 1, lines_err.size
81
+ assert_equal 'my-prog: something happened', lines_err[0]
82
+ end
83
+ end
84
+
85
+ # ############################## end of file ############################# #
86
+
87
+
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/ruby
2
2
  #
3
- # test minimal uses
3
+ # test simple scenarios
4
4
 
5
5
  $:.unshift File.join(File.dirname(__FILE__), '../..', 'lib')
6
6
 
File without changes
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.3.1
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Wilson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-13 00:00:00.000000000 Z
11
+ date: 2016-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clasp-ruby
@@ -57,17 +57,18 @@ executables: []
57
57
  extensions: []
58
58
  extra_rdoc_files: []
59
59
  files:
60
- - LICENSE
61
- - README.md
62
- - lib/libclimate.rb
63
60
  - lib/libclimate/climate.rb
64
61
  - lib/libclimate/libclimate.rb
65
62
  - lib/libclimate/version.rb
63
+ - lib/libclimate.rb
66
64
  - test/scratch/blankzeroes.rb
65
+ - test/unit/tc_abort.rb
67
66
  - test/unit/tc_minimal.rb
68
67
  - test/unit/tc_test_aliases.rb
69
68
  - test/unit/tc_with_blocks.rb
70
69
  - test/unit/ts_all.rb
70
+ - README.md
71
+ - LICENSE
71
72
  homepage: http://www.libclimate.org/
72
73
  licenses:
73
74
  - Modified BSD
@@ -88,8 +89,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
89
  version: '0'
89
90
  requirements: []
90
91
  rubyforge_project:
91
- rubygems_version: 2.4.2
92
+ rubygems_version: 2.0.14.1
92
93
  signing_key:
93
94
  specification_version: 4
94
95
  summary: libCLImate.Ruby
95
96
  test_files: []
97
+ has_rdoc: