libclimate-ruby 0.17.0 → 0.17.0.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 +4 -4
- data/examples/flag_and_option_specifications.from_DATA.rb +4 -4
- data/examples/flag_and_option_specifications.rb +22 -22
- data/examples/show_usage_and_version.rb +7 -7
- data/lib/libclimate/climate.rb +1000 -1000
- data/lib/libclimate/version.rb +14 -14
- data/test/scratch/blankzeroes.rb +14 -14
- data/test/scratch/specifications.rb +23 -23
- data/test/unit/tc_abort.rb +42 -42
- data/test/unit/tc_double_slash_index.rb +73 -73
- data/test/unit/tc_infer_version.rb +47 -47
- data/test/unit/tc_minimal.rb +516 -516
- data/test/unit/tc_minimal_CLASP.rb +323 -323
- data/test/unit/tc_parse.rb +104 -104
- data/test/unit/tc_parse_and_verify.rb +93 -93
- data/test/unit/tc_test_specifications.rb +48 -48
- data/test/unit/tc_values.rb +294 -294
- data/test/unit/tc_with_blocks.rb +18 -18
- data/test/unit/tc_with_blocks_CLASP.rb +18 -18
- metadata +6 -6
data/lib/libclimate/version.rb
CHANGED
@@ -4,11 +4,11 @@
|
|
4
4
|
# Purpose: Version for libclimate.Ruby library
|
5
5
|
#
|
6
6
|
# Created: 13th July 2015
|
7
|
-
# Updated:
|
7
|
+
# Updated: 6th March 2025
|
8
8
|
#
|
9
9
|
# Home: http://github.com/synesissoftware/libCLImate.Ruby
|
10
10
|
#
|
11
|
-
# Copyright (c) 2019-
|
11
|
+
# Copyright (c) 2019-2025, Matthew Wilson and Synesis Information Systems
|
12
12
|
# Copyright (c) 2015-2019, Matthew Wilson and Synesis Software
|
13
13
|
# All rights reserved.
|
14
14
|
#
|
@@ -43,18 +43,18 @@
|
|
43
43
|
|
44
44
|
module LibCLImate
|
45
45
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
46
|
+
# Current version of the libCLImate.Ruby library
|
47
|
+
VERSION = '0.17.0.1'
|
48
|
+
|
49
|
+
private
|
50
|
+
VERSION_PARTS_ = VERSION.split(/[.]/).collect { |n| n.to_i } # :nodoc:
|
51
|
+
public
|
52
|
+
# Major version of the libCLImate.Ruby library
|
53
|
+
VERSION_MAJOR = VERSION_PARTS_[0] # :nodoc:
|
54
|
+
# # Minor version of the libCLImate.Ruby library
|
55
|
+
VERSION_MINOR = VERSION_PARTS_[1] # :nodoc:
|
56
|
+
# # Revision version of the libCLImate.Ruby library
|
57
|
+
VERSION_REVISION = VERSION_PARTS_[2] # :nodoc:
|
58
58
|
end # module LibCLImate
|
59
59
|
|
60
60
|
|
data/test/scratch/blankzeroes.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
#!/usr/bin/ruby
|
2
2
|
|
3
3
|
#############################################################################
|
4
|
-
# File:
|
4
|
+
# File: test/scratch/blankzeroes.rb
|
5
5
|
#
|
6
|
-
# Purpose:
|
6
|
+
# Purpose: This filter program converts 0 values in a TSV into blanks
|
7
7
|
#
|
8
|
-
# Created:
|
9
|
-
# Updated:
|
8
|
+
# Created: 14th May 2016
|
9
|
+
# Updated: 6th March 2025
|
10
10
|
#
|
11
|
-
# Author:
|
11
|
+
# Author: Matthew Wilson
|
12
12
|
#
|
13
13
|
#############################################################################
|
14
14
|
|
@@ -20,21 +20,21 @@ require 'libclimate'
|
|
20
20
|
# ##########################################################
|
21
21
|
# constants
|
22
22
|
|
23
|
-
PROGRAM_VER_MAJOR
|
24
|
-
PROGRAM_VER_MINOR
|
25
|
-
PROGRAM_VER_PATCH
|
26
|
-
PROGRAM_VER_BUILD
|
23
|
+
PROGRAM_VER_MAJOR = 0
|
24
|
+
PROGRAM_VER_MINOR = 1
|
25
|
+
PROGRAM_VER_PATCH = 4
|
26
|
+
PROGRAM_VER_BUILD = 6
|
27
27
|
|
28
28
|
# ##########################################################
|
29
29
|
# command-line parsing
|
30
30
|
|
31
31
|
LibCLImate::Climate.new do |cl|
|
32
32
|
|
33
|
-
|
33
|
+
cl.info_lines = [
|
34
34
|
|
35
|
-
|
36
|
-
|
37
|
-
|
35
|
+
:version,
|
36
|
+
'converts 0 values into blanks',
|
37
|
+
]
|
38
38
|
end.run
|
39
39
|
|
40
40
|
# ##########################################################
|
@@ -42,7 +42,7 @@ end.run
|
|
42
42
|
|
43
43
|
$<.each_line do |line|
|
44
44
|
|
45
|
-
|
45
|
+
puts line.split(/\t/).map { |s| '0' == s ? '' : s }.join("\t")
|
46
46
|
end
|
47
47
|
|
48
48
|
# ############################## end of file ############################# #
|
@@ -1,14 +1,14 @@
|
|
1
1
|
#! /usr/bin/env ruby
|
2
2
|
|
3
3
|
#############################################################################
|
4
|
-
# File:
|
4
|
+
# File: test/scratch/specifications.rb
|
5
5
|
#
|
6
|
-
# Purpose:
|
6
|
+
# Purpose: Demonstrates use of specifications in options and flags
|
7
7
|
#
|
8
|
-
# Created:
|
9
|
-
# Updated:
|
8
|
+
# Created: 7th February 2018
|
9
|
+
# Updated: 6th March 2025
|
10
10
|
#
|
11
|
-
# Author:
|
11
|
+
# Author: Matthew Wilson
|
12
12
|
#
|
13
13
|
# Copyright: <<TBD>>
|
14
14
|
#
|
@@ -22,10 +22,10 @@ require 'libclimate'
|
|
22
22
|
# ##########################################################
|
23
23
|
# constants
|
24
24
|
|
25
|
-
PROGRAM_VER_MAJOR
|
26
|
-
PROGRAM_VER_MINOR
|
27
|
-
PROGRAM_VER_PATCH
|
28
|
-
PROGRAM_VER_BUILD
|
25
|
+
PROGRAM_VER_MAJOR = 0
|
26
|
+
PROGRAM_VER_MINOR = 1
|
27
|
+
PROGRAM_VER_PATCH = 2
|
28
|
+
PROGRAM_VER_BUILD = 1
|
29
29
|
|
30
30
|
# ##########################################################
|
31
31
|
# command-line parsing
|
@@ -34,25 +34,25 @@ options = {}
|
|
34
34
|
|
35
35
|
r = LibCLImate::Climate.new do |cl|
|
36
36
|
|
37
|
-
|
38
|
-
|
37
|
+
cl.add_flag('--verbose', alias: '-v', help: 'specifies verbosity') { options[:verbose] = true }
|
38
|
+
cl.add_alias('--verbose', '--V')
|
39
39
|
|
40
|
-
|
41
|
-
|
40
|
+
cl.add_option('--logging-threshold', alias: '-l', help: 'specifies the logging threshold') { |o, a| options[:logging_threshold] = o.value }
|
41
|
+
cl.add_alias('--logging-threshold=informational', '--I')
|
42
42
|
|
43
|
-
|
43
|
+
cl.info_lines = [
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
|
45
|
+
:version,
|
46
|
+
'demonstrates use of specifications',
|
47
|
+
]
|
48
48
|
|
49
|
-
|
49
|
+
cl.version = [
|
50
50
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
51
|
+
PROGRAM_VER_MAJOR,
|
52
|
+
PROGRAM_VER_MINOR,
|
53
|
+
PROGRAM_VER_PATCH,
|
54
|
+
PROGRAM_VER_BUILD,
|
55
|
+
]
|
56
56
|
end.run
|
57
57
|
|
58
58
|
|
data/test/unit/tc_abort.rb
CHANGED
@@ -15,71 +15,71 @@ require 'stringio'
|
|
15
15
|
|
16
16
|
class Test_Climate_abort < Test::Unit::TestCase
|
17
17
|
|
18
|
-
|
18
|
+
def test_abort_normal
|
19
19
|
|
20
|
-
|
21
|
-
|
20
|
+
strout = StringIO.new
|
21
|
+
strerr = StringIO.new
|
22
22
|
|
23
|
-
|
23
|
+
climate = LibCLImate::Climate.new do |cl|
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
cl.program_name = 'myprog'
|
26
|
+
cl.stdout = strout
|
27
|
+
cl.stderr = strerr
|
28
|
+
end
|
29
29
|
|
30
|
-
|
30
|
+
s = climate.abort 'something happened', exit: nil
|
31
31
|
|
32
|
-
|
32
|
+
lines_err = strerr.string.split /\n/
|
33
33
|
|
34
|
-
|
34
|
+
assert_equal 'myprog: something happened', s
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
assert_equal 1, lines_err.size
|
37
|
+
assert_equal 'myprog: something happened', lines_err[0]
|
38
|
+
end
|
39
39
|
|
40
|
-
|
40
|
+
def test_abort_no_program_name
|
41
41
|
|
42
|
-
|
43
|
-
|
42
|
+
strout = StringIO.new
|
43
|
+
strerr = StringIO.new
|
44
44
|
|
45
|
-
|
45
|
+
climate = LibCLImate::Climate.new do |cl|
|
46
46
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
47
|
+
cl.program_name = 'myprog'
|
48
|
+
cl.stdout = strout
|
49
|
+
cl.stderr = strerr
|
50
|
+
end
|
51
51
|
|
52
|
-
|
52
|
+
s = climate.abort 'something happened', exit: nil, program_name: ''
|
53
53
|
|
54
|
-
|
54
|
+
lines_err = strerr.string.split /\n/
|
55
55
|
|
56
|
-
|
56
|
+
assert_equal 'something happened', s
|
57
57
|
|
58
|
-
|
59
|
-
|
60
|
-
|
58
|
+
assert_equal 1, lines_err.size
|
59
|
+
assert_equal 'something happened', lines_err[0]
|
60
|
+
end
|
61
61
|
|
62
|
-
|
62
|
+
def test_abort_custom_program_name
|
63
63
|
|
64
|
-
|
65
|
-
|
64
|
+
strout = StringIO.new
|
65
|
+
strerr = StringIO.new
|
66
66
|
|
67
|
-
|
67
|
+
climate = LibCLImate::Climate.new do |cl|
|
68
68
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
69
|
+
cl.program_name = 'myprog'
|
70
|
+
cl.stdout = strout
|
71
|
+
cl.stderr = strerr
|
72
|
+
end
|
73
73
|
|
74
|
-
|
74
|
+
s = climate.abort 'something happened', exit: nil, program_name: 'my-prog'
|
75
75
|
|
76
|
-
|
76
|
+
lines_err = strerr.string.split /\n/
|
77
77
|
|
78
|
-
|
78
|
+
assert_equal 'my-prog: something happened', s
|
79
79
|
|
80
|
-
|
81
|
-
|
82
|
-
|
80
|
+
assert_equal 1, lines_err.size
|
81
|
+
assert_equal 'my-prog: something happened', lines_err[0]
|
82
|
+
end
|
83
83
|
end
|
84
84
|
|
85
85
|
# ############################## end of file ############################# #
|
@@ -15,77 +15,77 @@ require 'stringio'
|
|
15
15
|
|
16
16
|
class Test_Climate_double_slash_index < Test::Unit::TestCase
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
18
|
+
def test_some_arguments_without_DSI
|
19
|
+
|
20
|
+
climate = LibCLImate::Climate.new do |cl|
|
21
|
+
|
22
|
+
cl.add_flag('--abc')
|
23
|
+
|
24
|
+
cl.add_flag('-d')
|
25
|
+
cl.add_flag('-e')
|
26
|
+
cl.add_flag('-f')
|
27
|
+
end
|
28
|
+
|
29
|
+
argv = %w{ --abc -d -e -f }
|
30
|
+
|
31
|
+
r = climate.run argv
|
32
|
+
|
33
|
+
assert_not_nil r
|
34
|
+
assert_kind_of ::Hash, r
|
35
|
+
assert 3 <= r.size
|
36
|
+
assert_not_nil r[:flags]
|
37
|
+
assert_not_nil r[:options]
|
38
|
+
assert_not_nil r[:values]
|
39
|
+
assert_equal 4, r[:flags].size
|
40
|
+
assert_equal 4, r.flags.size
|
41
|
+
assert_equal 4, r[:flags][:given].size
|
42
|
+
assert_equal 0, r[:flags][:handled].size
|
43
|
+
assert_equal 4, r[:flags][:unhandled].size
|
44
|
+
assert_equal 0, r[:flags][:unknown].size
|
45
|
+
assert_equal 4, r[:options].size
|
46
|
+
assert_equal 0, r[:options][:given].size
|
47
|
+
assert_equal 0, r[:options][:handled].size
|
48
|
+
assert_equal 0, r[:options][:unhandled].size
|
49
|
+
assert_equal 0, r[:options][:unknown].size
|
50
|
+
assert_equal 0, r[:values].size
|
51
|
+
assert_nil r.double_slash_index
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_some_arguments_with_DSI
|
55
|
+
|
56
|
+
climate = LibCLImate::Climate.new do |cl|
|
57
|
+
|
58
|
+
cl.add_flag('--abc')
|
59
|
+
|
60
|
+
cl.add_flag('-d')
|
61
|
+
cl.add_flag('-e')
|
62
|
+
cl.add_flag('-f')
|
63
|
+
end
|
64
|
+
|
65
|
+
argv = %w{ --abc -d -- -e -f }
|
66
|
+
|
67
|
+
r = climate.run argv
|
68
|
+
|
69
|
+
assert_not_nil r
|
70
|
+
assert_kind_of ::Hash, r
|
71
|
+
assert 3 <= r.size
|
72
|
+
assert_not_nil r[:flags]
|
73
|
+
assert_not_nil r[:options]
|
74
|
+
assert_not_nil r[:values]
|
75
|
+
assert_equal 4, r[:flags].size
|
76
|
+
assert_equal 4, r.flags.size
|
77
|
+
assert_equal 2, r[:flags][:given].size
|
78
|
+
assert_equal 0, r[:flags][:handled].size
|
79
|
+
assert_equal 2, r[:flags][:unhandled].size
|
80
|
+
assert_equal 0, r[:flags][:unknown].size
|
81
|
+
assert_equal 4, r[:options].size
|
82
|
+
assert_equal 0, r[:options][:given].size
|
83
|
+
assert_equal 0, r[:options][:handled].size
|
84
|
+
assert_equal 0, r[:options][:unhandled].size
|
85
|
+
assert_equal 0, r[:options][:unknown].size
|
86
|
+
assert_equal 2, r[:values].size
|
87
|
+
assert_equal '-e', r[:values][0]
|
88
|
+
assert_equal '-f', r[:values][1]
|
89
|
+
assert_equal 2, r.double_slash_index
|
90
|
+
end
|
91
91
|
end
|
@@ -13,96 +13,96 @@ require 'test/unit'
|
|
13
13
|
|
14
14
|
require 'stringio'
|
15
15
|
|
16
|
-
PROGRAM_VER_MAJOR
|
16
|
+
PROGRAM_VER_MAJOR = 3
|
17
17
|
|
18
18
|
class Test_Climate_infer_version_3_22 < Test::Unit::TestCase
|
19
19
|
|
20
|
-
|
20
|
+
PROGRAM_VER_MINOR = 22
|
21
21
|
|
22
|
-
|
22
|
+
def test_inference_of_version
|
23
23
|
|
24
|
-
|
24
|
+
strout = StringIO.new
|
25
25
|
|
26
|
-
|
26
|
+
climate = LibCLImate::Climate.new(version_context: self) do |cl|
|
27
27
|
|
28
|
-
|
29
|
-
|
28
|
+
cl.program_name = 'myprog'
|
29
|
+
cl.stdout = strout
|
30
30
|
|
31
|
-
|
32
|
-
|
31
|
+
cl.exit_on_usage = false
|
32
|
+
end.run [ 'myprog', '--version' ]
|
33
33
|
|
34
|
-
|
34
|
+
s = strout.string
|
35
35
|
|
36
|
-
|
37
|
-
|
36
|
+
assert_equal "myprog 3.22", s.chomp
|
37
|
+
end
|
38
38
|
end
|
39
39
|
|
40
40
|
class Test_Climate_infer_version_3_2_99 < Test::Unit::TestCase
|
41
41
|
|
42
|
-
|
43
|
-
|
42
|
+
PROGRAM_VER_MINOR = 2
|
43
|
+
PROGRAM_VER_REVISION = 99
|
44
44
|
|
45
|
-
|
45
|
+
def test_inference_of_version
|
46
46
|
|
47
|
-
|
47
|
+
strout = StringIO.new
|
48
48
|
|
49
|
-
|
49
|
+
climate = LibCLImate::Climate.new(version_context: self) do |cl|
|
50
50
|
|
51
|
-
|
52
|
-
|
51
|
+
cl.program_name = 'myprog'
|
52
|
+
cl.stdout = strout
|
53
53
|
|
54
|
-
|
55
|
-
|
54
|
+
cl.exit_on_usage = false
|
55
|
+
end.run [ 'myprog', '--version' ]
|
56
56
|
|
57
|
-
|
57
|
+
s = strout.string
|
58
58
|
|
59
|
-
|
60
|
-
|
59
|
+
assert_equal "myprog 3.2.99", s.chomp
|
60
|
+
end
|
61
61
|
end
|
62
62
|
|
63
63
|
class Test_Climate_infer_PROGRAM_VERSION_as_array < Test::Unit::TestCase
|
64
64
|
|
65
|
-
|
65
|
+
PROGRAM_VERSION = [ 11, 12, 13 ]
|
66
66
|
|
67
|
-
|
67
|
+
def test_inference_of_version
|
68
68
|
|
69
|
-
|
69
|
+
strout = StringIO.new
|
70
70
|
|
71
|
-
|
71
|
+
climate = LibCLImate::Climate.new(version_context: self) do |cl|
|
72
72
|
|
73
|
-
|
74
|
-
|
73
|
+
cl.program_name = 'myprog'
|
74
|
+
cl.stdout = strout
|
75
75
|
|
76
|
-
|
77
|
-
|
76
|
+
cl.exit_on_usage = false
|
77
|
+
end.run [ 'myprog', '--version' ]
|
78
78
|
|
79
|
-
|
79
|
+
s = strout.string
|
80
80
|
|
81
|
-
|
82
|
-
|
81
|
+
assert_equal "myprog 11.12.13", s.chomp
|
82
|
+
end
|
83
83
|
end
|
84
84
|
|
85
85
|
class Test_Climate_infer_version_3_2_99_via_PATCH < Test::Unit::TestCase
|
86
86
|
|
87
|
-
|
88
|
-
|
87
|
+
PROGRAM_VER_MINOR = 7
|
88
|
+
PROGRAM_VER_PATCH = 101
|
89
89
|
|
90
|
-
|
90
|
+
def test_inference_of_version
|
91
91
|
|
92
|
-
|
92
|
+
strout = StringIO.new
|
93
93
|
|
94
|
-
|
94
|
+
climate = LibCLImate::Climate.new(version_context: self) do |cl|
|
95
95
|
|
96
|
-
|
97
|
-
|
96
|
+
cl.program_name = 'myprog'
|
97
|
+
cl.stdout = strout
|
98
98
|
|
99
|
-
|
100
|
-
|
99
|
+
cl.exit_on_usage = false
|
100
|
+
end.run [ 'myprog', '--version' ]
|
101
101
|
|
102
|
-
|
102
|
+
s = strout.string
|
103
103
|
|
104
|
-
|
105
|
-
|
104
|
+
assert_equal "myprog 3.7.101", s.chomp
|
105
|
+
end
|
106
106
|
end
|
107
107
|
|
108
108
|
# ############################## end of file ############################# #
|