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/test/unit/tc_parse.rb
CHANGED
@@ -15,163 +15,163 @@ require 'stringio'
|
|
15
15
|
|
16
16
|
class Test_Climate_parse < Test::Unit::TestCase
|
17
17
|
|
18
|
-
|
18
|
+
class VerifyException < RuntimeError; end
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
class MissingRequiredException < VerifyException; end
|
21
|
+
class UnrecognisedArgumentException < VerifyException; end
|
22
|
+
class UnusedArgumentException < VerifyException; end
|
23
23
|
|
24
|
-
|
24
|
+
def test_empty_specs_empty_args
|
25
25
|
|
26
|
-
|
27
|
-
|
26
|
+
stdout = StringIO.new
|
27
|
+
stderr = StringIO.new
|
28
28
|
|
29
|
-
|
29
|
+
climate = LibCLImate::Climate.new do |cl|
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
cl.stdout = $stdout
|
32
|
+
cl.stderr = $stderr
|
33
|
+
end
|
34
34
|
|
35
|
-
|
36
|
-
|
35
|
+
assert $stdout.equal? climate.stdout
|
36
|
+
assert $stderr.equal? climate.stderr
|
37
37
|
|
38
|
-
|
39
|
-
|
38
|
+
argv = [
|
39
|
+
]
|
40
40
|
|
41
|
-
|
41
|
+
r = climate.parse argv
|
42
42
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
43
|
+
assert_eql climate, r.climate
|
44
|
+
assert_equal 0, r.flags.size
|
45
|
+
assert_equal 0, r.options.size
|
46
|
+
assert_equal 0, r.values.size
|
47
|
+
assert_nil r.double_slash_index
|
48
48
|
|
49
|
-
|
50
|
-
|
49
|
+
r.verify()
|
50
|
+
end
|
51
51
|
|
52
|
-
|
52
|
+
def test_one_flag_with_block
|
53
53
|
|
54
|
-
|
55
|
-
|
54
|
+
stdout = StringIO.new
|
55
|
+
stderr = StringIO.new
|
56
56
|
|
57
|
-
|
57
|
+
debug = false
|
58
58
|
|
59
|
-
|
59
|
+
climate = LibCLImate::Climate.new do |cl|
|
60
60
|
|
61
|
-
|
61
|
+
cl.add_flag('--debug', alias: '-d') { debug = true }
|
62
62
|
|
63
|
-
|
64
|
-
|
65
|
-
|
63
|
+
cl.stdout = $stdout
|
64
|
+
cl.stderr = $stderr
|
65
|
+
end
|
66
66
|
|
67
|
-
|
68
|
-
|
67
|
+
assert $stdout.equal? climate.stdout
|
68
|
+
assert $stderr.equal? climate.stderr
|
69
69
|
|
70
|
-
|
70
|
+
argv = [
|
71
71
|
|
72
|
-
|
73
|
-
|
74
|
-
|
72
|
+
'-d',
|
73
|
+
'--',
|
74
|
+
]
|
75
75
|
|
76
|
-
|
76
|
+
r = climate.parse argv
|
77
77
|
|
78
|
-
|
78
|
+
assert_false debug
|
79
79
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
80
|
+
assert_eql climate, r.climate
|
81
|
+
assert_equal 1, r.flags.size
|
82
|
+
assert_equal 0, r.options.size
|
83
|
+
assert_equal 0, r.values.size
|
84
|
+
assert_equal 1, r.double_slash_index
|
85
85
|
|
86
|
-
|
86
|
+
flag0 = r.flags[0]
|
87
87
|
|
88
|
-
|
89
|
-
|
88
|
+
assert_equal '-d', flag0.given_name
|
89
|
+
assert_equal '--debug', flag0.name
|
90
90
|
|
91
|
-
|
91
|
+
r.verify()
|
92
92
|
|
93
|
-
|
94
|
-
|
93
|
+
assert_true debug
|
94
|
+
end
|
95
95
|
|
96
|
-
|
96
|
+
def test_one_option_with_block
|
97
97
|
|
98
|
-
|
99
|
-
|
98
|
+
stdout = StringIO.new
|
99
|
+
stderr = StringIO.new
|
100
100
|
|
101
|
-
|
101
|
+
verb = nil
|
102
102
|
|
103
|
-
|
103
|
+
climate = LibCLImate::Climate.new do |cl|
|
104
104
|
|
105
|
-
|
105
|
+
cl.add_option('--verbosity', alias: '-v') do |o, s|
|
106
106
|
|
107
|
-
|
108
|
-
|
107
|
+
verb = o.value
|
108
|
+
end
|
109
109
|
|
110
|
-
|
111
|
-
|
112
|
-
|
110
|
+
cl.stdout = $stdout
|
111
|
+
cl.stderr = $stderr
|
112
|
+
end
|
113
113
|
|
114
|
-
|
115
|
-
|
114
|
+
assert $stdout.equal? climate.stdout
|
115
|
+
assert $stderr.equal? climate.stderr
|
116
116
|
|
117
|
-
|
117
|
+
argv = [
|
118
118
|
|
119
|
-
|
120
|
-
|
121
|
-
|
119
|
+
'-v',
|
120
|
+
'chatty',
|
121
|
+
]
|
122
122
|
|
123
|
-
|
123
|
+
r = climate.parse argv
|
124
124
|
|
125
|
-
|
125
|
+
assert_nil verb
|
126
126
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
127
|
+
assert_eql climate, r.climate
|
128
|
+
assert_equal 0, r.flags.size
|
129
|
+
assert_equal 1, r.options.size
|
130
|
+
assert_equal 0, r.values.size
|
131
|
+
assert_nil r.double_slash_index
|
132
132
|
|
133
|
-
|
133
|
+
option0 = r.options[0]
|
134
134
|
|
135
|
-
|
136
|
-
|
135
|
+
assert_equal '-v', option0.given_name
|
136
|
+
assert_equal '--verbosity', option0.name
|
137
137
|
|
138
|
-
|
138
|
+
r.verify()
|
139
139
|
|
140
|
-
|
141
|
-
|
140
|
+
assert_equal 'chatty', verb
|
141
|
+
end
|
142
142
|
|
143
|
-
|
143
|
+
def test_one_required_flag_that_is_missing
|
144
144
|
|
145
|
-
|
146
|
-
|
145
|
+
stdout = StringIO.new
|
146
|
+
stderr = StringIO.new
|
147
147
|
|
148
|
-
|
148
|
+
climate = LibCLImate::Climate.new do |cl|
|
149
149
|
|
150
|
-
|
150
|
+
cl.add_option('--verbosity', alias: '-v', required: true) do |o, s|
|
151
151
|
|
152
|
-
|
153
|
-
|
152
|
+
verb = o.value
|
153
|
+
end
|
154
154
|
|
155
|
-
|
156
|
-
|
157
|
-
|
155
|
+
cl.stdout = $stdout
|
156
|
+
cl.stderr = $stderr
|
157
|
+
end
|
158
158
|
|
159
|
-
|
160
|
-
|
159
|
+
assert $stdout.equal? climate.stdout
|
160
|
+
assert $stderr.equal? climate.stderr
|
161
161
|
|
162
|
-
|
163
|
-
|
164
|
-
|
162
|
+
argv = [
|
163
|
+
'--',
|
164
|
+
]
|
165
165
|
|
166
|
-
|
166
|
+
r = climate.parse argv
|
167
167
|
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
168
|
+
assert_eql climate, r.climate
|
169
|
+
assert_equal 0, r.flags.size
|
170
|
+
assert_equal 0, r.options.size
|
171
|
+
assert_equal 0, r.values.size
|
172
|
+
assert_equal 0, r.double_slash_index
|
173
173
|
|
174
|
-
|
175
|
-
|
174
|
+
assert_raise_with_message(MissingRequiredException, /.*verbosity.*not specified/) { r.verify(raise_on_required: MissingRequiredException) }
|
175
|
+
end
|
176
176
|
end
|
177
177
|
|
@@ -15,146 +15,146 @@ require 'stringio'
|
|
15
15
|
|
16
16
|
class Test_Climate_parse_and_verify < Test::Unit::TestCase
|
17
17
|
|
18
|
-
|
18
|
+
class VerifyException < RuntimeError; end
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
class MissingRequiredException < VerifyException; end
|
21
|
+
class UnrecognisedArgumentException < VerifyException; end
|
22
|
+
class UnusedArgumentException < VerifyException; end
|
23
23
|
|
24
|
-
|
24
|
+
def test_empty_specs_empty_args
|
25
25
|
|
26
|
-
|
27
|
-
|
26
|
+
stdout = StringIO.new
|
27
|
+
stderr = StringIO.new
|
28
28
|
|
29
|
-
|
29
|
+
climate = LibCLImate::Climate.new do |cl|
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
cl.stdout = $stdout
|
32
|
+
cl.stderr = $stderr
|
33
|
+
end
|
34
34
|
|
35
|
-
|
36
|
-
|
35
|
+
assert $stdout.equal? climate.stdout
|
36
|
+
assert $stderr.equal? climate.stderr
|
37
37
|
|
38
|
-
|
39
|
-
|
38
|
+
argv = [
|
39
|
+
]
|
40
40
|
|
41
|
-
|
41
|
+
r = climate.parse_and_verify argv
|
42
42
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
43
|
+
assert_eql climate, r.climate
|
44
|
+
assert_equal 0, r.flags.size
|
45
|
+
assert_equal 0, r.options.size
|
46
|
+
assert_equal 0, r.values.size
|
47
|
+
assert_nil r.double_slash_index
|
48
|
+
end
|
49
49
|
|
50
|
-
|
50
|
+
def test_one_flag_with_block
|
51
51
|
|
52
|
-
|
53
|
-
|
52
|
+
stdout = StringIO.new
|
53
|
+
stderr = StringIO.new
|
54
54
|
|
55
|
-
|
55
|
+
debug = false
|
56
56
|
|
57
|
-
|
57
|
+
climate = LibCLImate::Climate.new do |cl|
|
58
58
|
|
59
|
-
|
59
|
+
cl.add_flag('--debug', alias: '-d') { debug = true }
|
60
60
|
|
61
|
-
|
62
|
-
|
63
|
-
|
61
|
+
cl.stdout = $stdout
|
62
|
+
cl.stderr = $stderr
|
63
|
+
end
|
64
64
|
|
65
|
-
|
66
|
-
|
65
|
+
assert $stdout.equal? climate.stdout
|
66
|
+
assert $stderr.equal? climate.stderr
|
67
67
|
|
68
|
-
|
68
|
+
argv = [
|
69
69
|
|
70
|
-
|
71
|
-
|
70
|
+
'-d',
|
71
|
+
]
|
72
72
|
|
73
|
-
|
73
|
+
r = climate.parse_and_verify argv
|
74
74
|
|
75
|
-
|
75
|
+
assert_true debug
|
76
76
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
77
|
+
assert_eql climate, r.climate
|
78
|
+
assert_equal 1, r.flags.size
|
79
|
+
assert_equal 0, r.options.size
|
80
|
+
assert_equal 0, r.values.size
|
81
|
+
assert_nil r.double_slash_index
|
82
82
|
|
83
|
-
|
83
|
+
flag0 = r.flags[0]
|
84
84
|
|
85
|
-
|
86
|
-
|
87
|
-
|
85
|
+
assert_equal '-d', flag0.given_name
|
86
|
+
assert_equal '--debug', flag0.name
|
87
|
+
end
|
88
88
|
|
89
|
-
|
89
|
+
def test_one_option_with_block
|
90
90
|
|
91
|
-
|
92
|
-
|
91
|
+
stdout = StringIO.new
|
92
|
+
stderr = StringIO.new
|
93
93
|
|
94
|
-
|
94
|
+
verb = nil
|
95
95
|
|
96
|
-
|
96
|
+
climate = LibCLImate::Climate.new do |cl|
|
97
97
|
|
98
|
-
|
98
|
+
cl.add_option('--verbosity', alias: '-v') do |o, s|
|
99
99
|
|
100
|
-
|
101
|
-
|
100
|
+
verb = o.value
|
101
|
+
end
|
102
102
|
|
103
|
-
|
104
|
-
|
105
|
-
|
103
|
+
cl.stdout = $stdout
|
104
|
+
cl.stderr = $stderr
|
105
|
+
end
|
106
106
|
|
107
|
-
|
108
|
-
|
107
|
+
assert $stdout.equal? climate.stdout
|
108
|
+
assert $stderr.equal? climate.stderr
|
109
109
|
|
110
|
-
|
110
|
+
argv = [
|
111
111
|
|
112
|
-
|
113
|
-
|
114
|
-
|
112
|
+
'-v',
|
113
|
+
'chatty',
|
114
|
+
]
|
115
115
|
|
116
|
-
|
116
|
+
r = climate.parse_and_verify argv
|
117
117
|
|
118
|
-
|
118
|
+
assert_equal 'chatty', verb
|
119
119
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
120
|
+
assert_eql climate, r.climate
|
121
|
+
assert_equal 0, r.flags.size
|
122
|
+
assert_equal 1, r.options.size
|
123
|
+
assert_equal 0, r.values.size
|
124
|
+
assert_nil r.double_slash_index
|
125
125
|
|
126
|
-
|
126
|
+
option0 = r.options[0]
|
127
127
|
|
128
|
-
|
129
|
-
|
130
|
-
|
128
|
+
assert_equal '-v', option0.given_name
|
129
|
+
assert_equal '--verbosity', option0.name
|
130
|
+
end
|
131
131
|
|
132
|
-
|
132
|
+
def test_one_required_flag_that_is_missing
|
133
133
|
|
134
|
-
|
135
|
-
|
134
|
+
stdout = StringIO.new
|
135
|
+
stderr = StringIO.new
|
136
136
|
|
137
|
-
|
137
|
+
climate = LibCLImate::Climate.new do |cl|
|
138
138
|
|
139
|
-
|
139
|
+
cl.add_option('--verbosity', alias: '-v', required: true) do |o, s|
|
140
140
|
|
141
|
-
|
142
|
-
|
141
|
+
verb = o.value
|
142
|
+
end
|
143
143
|
|
144
|
-
|
145
|
-
|
146
|
-
|
144
|
+
cl.stdout = $stdout
|
145
|
+
cl.stderr = $stderr
|
146
|
+
end
|
147
147
|
|
148
|
-
|
149
|
-
|
148
|
+
assert $stdout.equal? climate.stdout
|
149
|
+
assert $stderr.equal? climate.stderr
|
150
150
|
|
151
|
-
|
152
|
-
|
151
|
+
argv = [
|
152
|
+
]
|
153
153
|
|
154
|
-
|
154
|
+
assert_raise_with_message(MissingRequiredException, /.*verbosity.*not specified/) do
|
155
155
|
|
156
|
-
|
157
|
-
|
158
|
-
|
156
|
+
climate.parse_and_verify argv, raise_on_required: MissingRequiredException
|
157
|
+
end
|
158
|
+
end
|
159
159
|
end
|
160
160
|
|
@@ -15,74 +15,74 @@ require 'stringio'
|
|
15
15
|
|
16
16
|
class Test_Climate_minimal < Test::Unit::TestCase
|
17
17
|
|
18
|
-
|
18
|
+
def test_option_with_flag_specifications
|
19
19
|
|
20
|
-
|
20
|
+
options = {}
|
21
21
|
|
22
|
-
|
22
|
+
climate = LibCLImate::Climate.new do |cl|
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
cl.add_option('--action', alias: '-a') { |o, a| options[:action] = o.value }
|
25
|
+
cl.add_alias('--action=list', '-l')
|
26
|
+
cl.add_alias('--action=change', '-c')
|
27
|
+
end
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
# invoke via option
|
30
|
+
begin
|
31
|
+
options = {}
|
32
32
|
|
33
|
-
|
33
|
+
argv = %w{ --action=action1 }
|
34
34
|
|
35
|
-
|
35
|
+
r = climate.run argv
|
36
36
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
37
|
+
assert_not_nil r
|
38
|
+
assert_kind_of ::Hash, r
|
39
|
+
assert 3 <= r.size
|
40
|
+
assert_equal 0, r.flags[:given].size
|
41
41
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
42
|
+
assert_equal 1, options.size
|
43
|
+
assert_not_nil options[:action]
|
44
|
+
assert_equal 'action1', options[:action]
|
45
|
+
end
|
46
46
|
|
47
|
-
|
48
|
-
|
49
|
-
|
47
|
+
# invoke via option specification
|
48
|
+
begin
|
49
|
+
options = {}
|
50
50
|
|
51
|
-
|
51
|
+
argv = %w{ -a action2 }
|
52
52
|
|
53
|
-
|
53
|
+
r = climate.run argv
|
54
54
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
55
|
+
assert_equal 1, options.size
|
56
|
+
assert_not_nil options[:action]
|
57
|
+
assert_equal 'action2', options[:action]
|
58
|
+
end
|
59
59
|
|
60
|
-
|
61
|
-
|
62
|
-
|
60
|
+
# invoke via flag specification
|
61
|
+
begin
|
62
|
+
options = {}
|
63
63
|
|
64
|
-
|
64
|
+
argv = %w{ -c }
|
65
65
|
|
66
|
-
|
66
|
+
r = climate.run argv
|
67
67
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
68
|
+
assert_equal 1, options.size
|
69
|
+
assert_not_nil options[:action]
|
70
|
+
assert_equal 'change', options[:action]
|
71
|
+
end
|
72
72
|
|
73
|
-
|
74
|
-
|
75
|
-
|
73
|
+
# invoke via flag specification
|
74
|
+
begin
|
75
|
+
options = {}
|
76
76
|
|
77
|
-
|
77
|
+
argv = %w{ -l }
|
78
78
|
|
79
|
-
|
79
|
+
r = climate.run argv
|
80
80
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
81
|
+
assert_equal 1, options.size
|
82
|
+
assert_not_nil options[:action]
|
83
|
+
assert_equal 'list', options[:action]
|
84
|
+
end
|
85
|
+
end
|
86
86
|
end
|
87
87
|
|
88
88
|
# ############################## end of file ############################# #
|