cri 2.7.0 → 2.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +3 -3
- data/Gemfile.lock +15 -13
- data/NEWS.md +7 -0
- data/README.adoc +5 -5
- data/Rakefile +5 -3
- data/cri.gemspec +2 -2
- data/lib/cri.rb +1 -3
- data/lib/cri/argument_array.rb +0 -2
- data/lib/cri/command.rb +17 -19
- data/lib/cri/command_dsl.rb +16 -18
- data/lib/cri/command_runner.rb +1 -3
- data/lib/cri/commands/basic_help.rb +5 -7
- data/lib/cri/commands/basic_root.rb +0 -2
- data/lib/cri/core_ext.rb +0 -2
- data/lib/cri/core_ext/string.rb +0 -2
- data/lib/cri/help_renderer.rb +6 -13
- data/lib/cri/option_parser.rb +10 -12
- data/lib/cri/platform.rb +0 -2
- data/lib/cri/string_formatter.rb +1 -3
- data/lib/cri/version.rb +1 -3
- data/test/helper.rb +3 -5
- data/test/test_argument_array.rb +0 -2
- data/test/test_base.rb +1 -4
- data/test/test_basic_help.rb +0 -2
- data/test/test_basic_root.rb +1 -3
- data/test/test_command.rb +25 -27
- data/test/test_command_dsl.rb +30 -32
- data/test/test_command_runner.rb +2 -4
- data/test/test_option_parser.rb +60 -62
- data/test/test_string_formatter.rb +0 -2
- metadata +6 -7
data/test/test_command_runner.rb
CHANGED
@@ -1,12 +1,10 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
module Cri
|
4
2
|
class CommandRunnerTestCase < Cri::TestCase
|
5
3
|
def setup
|
6
4
|
super
|
7
5
|
|
8
|
-
@options = { :
|
9
|
-
@arguments = %w(
|
6
|
+
@options = { vehicle: 'pig' }
|
7
|
+
@arguments = %w(baby_monkey)
|
10
8
|
@command = Cri::Command.new
|
11
9
|
end
|
12
10
|
|
data/test/test_option_parser.rb
CHANGED
@@ -1,19 +1,17 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
module Cri
|
4
2
|
class OptionParserTestCase < Cri::TestCase
|
5
3
|
def test_parse_without_options
|
6
|
-
input = %w(
|
4
|
+
input = %w(foo bar baz)
|
7
5
|
definitions = []
|
8
6
|
|
9
7
|
parser = Cri::OptionParser.parse(input, definitions)
|
10
8
|
|
11
|
-
assert_equal({},
|
9
|
+
assert_equal({}, parser.options)
|
12
10
|
assert_equal(%w(foo bar baz), parser.arguments)
|
13
11
|
end
|
14
12
|
|
15
13
|
def test_parse_with_invalid_option
|
16
|
-
input = %w(
|
14
|
+
input = %w(foo -x)
|
17
15
|
definitions = []
|
18
16
|
|
19
17
|
assert_raises(Cri::OptionParser::IllegalOptionError) do
|
@@ -22,9 +20,9 @@ module Cri
|
|
22
20
|
end
|
23
21
|
|
24
22
|
def test_parse_with_unused_options
|
25
|
-
input = %w(
|
23
|
+
input = %w(foo)
|
26
24
|
definitions = [
|
27
|
-
{ :
|
25
|
+
{ long: 'aaa', short: 'a', argument: :forbidden },
|
28
26
|
]
|
29
27
|
|
30
28
|
parser = Cri::OptionParser.parse(input, definitions)
|
@@ -33,9 +31,9 @@ module Cri
|
|
33
31
|
end
|
34
32
|
|
35
33
|
def test_parse_with_long_valueless_option
|
36
|
-
input = %w(
|
34
|
+
input = %w(foo --aaa bar)
|
37
35
|
definitions = [
|
38
|
-
{ :
|
36
|
+
{ long: 'aaa', short: 'a', argument: :forbidden },
|
39
37
|
]
|
40
38
|
|
41
39
|
parser = Cri::OptionParser.parse(input, definitions)
|
@@ -45,33 +43,33 @@ module Cri
|
|
45
43
|
end
|
46
44
|
|
47
45
|
def test_parse_with_long_valueful_option
|
48
|
-
input = %w(
|
46
|
+
input = %w(foo --aaa xxx bar)
|
49
47
|
definitions = [
|
50
|
-
{ :
|
48
|
+
{ long: 'aaa', short: 'a', argument: :required },
|
51
49
|
]
|
52
50
|
|
53
51
|
parser = Cri::OptionParser.parse(input, definitions)
|
54
52
|
|
55
|
-
assert_equal({ :
|
53
|
+
assert_equal({ aaa: 'xxx' }, parser.options)
|
56
54
|
assert_equal(%w(foo bar), parser.arguments)
|
57
55
|
end
|
58
56
|
|
59
57
|
def test_parse_with_long_valueful_equalsign_option
|
60
|
-
input = %w(
|
58
|
+
input = %w(foo --aaa=xxx bar)
|
61
59
|
definitions = [
|
62
|
-
{ :
|
60
|
+
{ long: 'aaa', short: 'a', argument: :required },
|
63
61
|
]
|
64
62
|
|
65
63
|
parser = Cri::OptionParser.parse(input, definitions)
|
66
64
|
|
67
|
-
assert_equal({ :
|
65
|
+
assert_equal({ aaa: 'xxx' }, parser.options)
|
68
66
|
assert_equal(%w(foo bar), parser.arguments)
|
69
67
|
end
|
70
68
|
|
71
69
|
def test_parse_with_long_valueful_option_with_missing_value
|
72
|
-
input = %w(
|
70
|
+
input = %w(foo --aaa)
|
73
71
|
definitions = [
|
74
|
-
{ :
|
72
|
+
{ long: 'aaa', short: 'a', argument: :required },
|
75
73
|
]
|
76
74
|
|
77
75
|
assert_raises(Cri::OptionParser::OptionRequiresAnArgumentError) do
|
@@ -80,10 +78,10 @@ module Cri
|
|
80
78
|
end
|
81
79
|
|
82
80
|
def test_parse_with_two_long_valueful_options
|
83
|
-
input = %w(
|
81
|
+
input = %w(foo --all --port 2)
|
84
82
|
definitions = [
|
85
|
-
{ :
|
86
|
-
{ :
|
83
|
+
{ long: 'all', short: 'a', argument: :required },
|
84
|
+
{ long: 'port', short: 'p', argument: :required },
|
87
85
|
]
|
88
86
|
|
89
87
|
assert_raises(Cri::OptionParser::OptionRequiresAnArgumentError) do
|
@@ -92,9 +90,9 @@ module Cri
|
|
92
90
|
end
|
93
91
|
|
94
92
|
def test_parse_with_long_valueless_option_with_optional_value
|
95
|
-
input = %w(
|
93
|
+
input = %w(foo --aaa)
|
96
94
|
definitions = [
|
97
|
-
{ :
|
95
|
+
{ long: 'aaa', short: 'a', argument: :optional },
|
98
96
|
]
|
99
97
|
|
100
98
|
parser = Cri::OptionParser.parse(input, definitions)
|
@@ -104,23 +102,23 @@ module Cri
|
|
104
102
|
end
|
105
103
|
|
106
104
|
def test_parse_with_long_valueful_option_with_optional_value
|
107
|
-
input = %w(
|
105
|
+
input = %w(foo --aaa xxx)
|
108
106
|
definitions = [
|
109
|
-
{ :
|
107
|
+
{ long: 'aaa', short: 'a', argument: :optional },
|
110
108
|
]
|
111
109
|
|
112
110
|
parser = Cri::OptionParser.parse(input, definitions)
|
113
111
|
|
114
|
-
assert_equal({ :
|
112
|
+
assert_equal({ aaa: 'xxx' }, parser.options)
|
115
113
|
assert_equal(['foo'], parser.arguments)
|
116
114
|
end
|
117
115
|
|
118
116
|
def test_parse_with_long_valueless_option_with_optional_value_and_more_options
|
119
|
-
input = %w(
|
117
|
+
input = %w(foo --aaa -b -c)
|
120
118
|
definitions = [
|
121
|
-
{ :
|
122
|
-
{ :
|
123
|
-
{ :
|
119
|
+
{ long: 'aaa', short: 'a', argument: :optional },
|
120
|
+
{ long: 'bbb', short: 'b', argument: :forbidden },
|
121
|
+
{ long: 'ccc', short: 'c', argument: :forbidden },
|
124
122
|
]
|
125
123
|
|
126
124
|
parser = Cri::OptionParser.parse(input, definitions)
|
@@ -132,9 +130,9 @@ module Cri
|
|
132
130
|
end
|
133
131
|
|
134
132
|
def test_parse_with_short_valueless_options
|
135
|
-
input = %w(
|
133
|
+
input = %w(foo -a bar)
|
136
134
|
definitions = [
|
137
|
-
{ :
|
135
|
+
{ long: 'aaa', short: 'a', argument: :forbidden },
|
138
136
|
]
|
139
137
|
|
140
138
|
parser = Cri::OptionParser.parse(input, definitions)
|
@@ -144,9 +142,9 @@ module Cri
|
|
144
142
|
end
|
145
143
|
|
146
144
|
def test_parse_with_short_valueful_option_with_missing_value
|
147
|
-
input = %w(
|
145
|
+
input = %w(foo -a)
|
148
146
|
definitions = [
|
149
|
-
{ :
|
147
|
+
{ long: 'aaa', short: 'a', argument: :required },
|
150
148
|
]
|
151
149
|
|
152
150
|
assert_raises(Cri::OptionParser::OptionRequiresAnArgumentError) do
|
@@ -155,11 +153,11 @@ module Cri
|
|
155
153
|
end
|
156
154
|
|
157
155
|
def test_parse_with_short_combined_valueless_options
|
158
|
-
input = %w(
|
156
|
+
input = %w(foo -abc bar)
|
159
157
|
definitions = [
|
160
|
-
{ :
|
161
|
-
{ :
|
162
|
-
{ :
|
158
|
+
{ long: 'aaa', short: 'a', argument: :forbidden },
|
159
|
+
{ long: 'bbb', short: 'b', argument: :forbidden },
|
160
|
+
{ long: 'ccc', short: 'c', argument: :forbidden },
|
163
161
|
]
|
164
162
|
|
165
163
|
parser = Cri::OptionParser.parse(input, definitions)
|
@@ -171,11 +169,11 @@ module Cri
|
|
171
169
|
end
|
172
170
|
|
173
171
|
def test_parse_with_short_combined_valueful_options_with_missing_value
|
174
|
-
input = %w(
|
172
|
+
input = %w(foo -abc bar)
|
175
173
|
definitions = [
|
176
|
-
{ :
|
177
|
-
{ :
|
178
|
-
{ :
|
174
|
+
{ long: 'aaa', short: 'a', argument: :required },
|
175
|
+
{ long: 'bbb', short: 'b', argument: :forbidden },
|
176
|
+
{ long: 'ccc', short: 'c', argument: :forbidden },
|
179
177
|
]
|
180
178
|
|
181
179
|
assert_raises(Cri::OptionParser::OptionRequiresAnArgumentError) do
|
@@ -184,10 +182,10 @@ module Cri
|
|
184
182
|
end
|
185
183
|
|
186
184
|
def test_parse_with_two_short_valueful_options
|
187
|
-
input = %w(
|
185
|
+
input = %w(foo -a -p 2)
|
188
186
|
definitions = [
|
189
|
-
{ :
|
190
|
-
{ :
|
187
|
+
{ long: 'all', short: 'a', argument: :required },
|
188
|
+
{ long: 'port', short: 'p', argument: :required },
|
191
189
|
]
|
192
190
|
|
193
191
|
assert_raises(Cri::OptionParser::OptionRequiresAnArgumentError) do
|
@@ -196,9 +194,9 @@ module Cri
|
|
196
194
|
end
|
197
195
|
|
198
196
|
def test_parse_with_short_valueless_option_with_optional_value
|
199
|
-
input = %w(
|
197
|
+
input = %w(foo -a)
|
200
198
|
definitions = [
|
201
|
-
{ :
|
199
|
+
{ long: 'aaa', short: 'a', argument: :optional },
|
202
200
|
]
|
203
201
|
|
204
202
|
parser = Cri::OptionParser.parse(input, definitions)
|
@@ -208,23 +206,23 @@ module Cri
|
|
208
206
|
end
|
209
207
|
|
210
208
|
def test_parse_with_short_valueful_option_with_optional_value
|
211
|
-
input = %w(
|
209
|
+
input = %w(foo -a xxx)
|
212
210
|
definitions = [
|
213
|
-
{ :
|
211
|
+
{ long: 'aaa', short: 'a', argument: :optional },
|
214
212
|
]
|
215
213
|
|
216
214
|
parser = Cri::OptionParser.parse(input, definitions)
|
217
215
|
|
218
|
-
assert_equal({ :
|
216
|
+
assert_equal({ aaa: 'xxx' }, parser.options)
|
219
217
|
assert_equal(['foo'], parser.arguments)
|
220
218
|
end
|
221
219
|
|
222
220
|
def test_parse_with_short_valueless_option_with_optional_value_and_more_options
|
223
|
-
input = %w(
|
221
|
+
input = %w(foo -a -b -c)
|
224
222
|
definitions = [
|
225
|
-
{ :
|
226
|
-
{ :
|
227
|
-
{ :
|
223
|
+
{ long: 'aaa', short: 'a', argument: :optional },
|
224
|
+
{ long: 'bbb', short: 'b', argument: :forbidden },
|
225
|
+
{ long: 'ccc', short: 'c', argument: :forbidden },
|
228
226
|
]
|
229
227
|
|
230
228
|
parser = Cri::OptionParser.parse(input, definitions)
|
@@ -236,30 +234,30 @@ module Cri
|
|
236
234
|
end
|
237
235
|
|
238
236
|
def test_parse_with_single_hyphen
|
239
|
-
input = %w(
|
237
|
+
input = %w(foo - bar)
|
240
238
|
definitions = []
|
241
239
|
|
242
240
|
parser = Cri::OptionParser.parse(input, definitions)
|
243
241
|
|
244
|
-
assert_equal({},
|
242
|
+
assert_equal({}, parser.options)
|
245
243
|
assert_equal(['foo', '-', 'bar'], parser.arguments)
|
246
244
|
end
|
247
245
|
|
248
246
|
def test_parse_with_end_marker
|
249
|
-
input = %w(
|
247
|
+
input = %w(foo bar -- -x --yyy -abc)
|
250
248
|
definitions = []
|
251
249
|
|
252
250
|
parser = Cri::OptionParser.parse(input, definitions)
|
253
251
|
|
254
|
-
assert_equal({},
|
252
|
+
assert_equal({}, parser.options)
|
255
253
|
assert_equal(['foo', 'bar', '-x', '--yyy', '-abc'], parser.arguments)
|
256
254
|
assert_equal(['foo', 'bar', '--', '-x', '--yyy', '-abc'], parser.arguments.raw)
|
257
255
|
end
|
258
256
|
|
259
257
|
def test_parse_with_end_marker_between_option_key_and_value
|
260
|
-
input = %w(
|
258
|
+
input = %w(foo --aaa -- zzz)
|
261
259
|
definitions = [
|
262
|
-
{ :
|
260
|
+
{ long: 'aaa', short: 'a', argument: :required },
|
263
261
|
]
|
264
262
|
|
265
263
|
assert_raises(Cri::OptionParser::OptionRequiresAnArgumentError) do
|
@@ -268,10 +266,10 @@ module Cri
|
|
268
266
|
end
|
269
267
|
|
270
268
|
def test_parse_with_multiple_options
|
271
|
-
input = %w(
|
269
|
+
input = %w(foo -o test -o test2 -v -v -v)
|
272
270
|
definitions = [
|
273
|
-
{ :
|
274
|
-
{ :
|
271
|
+
{ long: 'long', short: 'o', argument: :required, multiple: true },
|
272
|
+
{ long: 'verbose', short: 'v', multiple: true },
|
275
273
|
]
|
276
274
|
parser = Cri::OptionParser.parse(input, definitions)
|
277
275
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cri
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.7.
|
4
|
+
version: 2.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Denis Defreyne
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-12-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colored
|
@@ -38,8 +38,8 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.6'
|
41
|
-
description: Cri allows building easy-to-use
|
42
|
-
subcommands.
|
41
|
+
description: Cri allows building easy-to-use command-line interfaces with support
|
42
|
+
for subcommands.
|
43
43
|
email: denis.defreyne@stoneship.org
|
44
44
|
executables: []
|
45
45
|
extensions: []
|
@@ -101,9 +101,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
101
|
version: '0'
|
102
102
|
requirements: []
|
103
103
|
rubyforge_project:
|
104
|
-
rubygems_version: 2.
|
104
|
+
rubygems_version: 2.6.8
|
105
105
|
signing_key:
|
106
106
|
specification_version: 4
|
107
|
-
summary: a library for building easy-to-use
|
107
|
+
summary: a library for building easy-to-use command-line tools
|
108
108
|
test_files: []
|
109
|
-
has_rdoc:
|