como 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.rdoc +15 -0
- data/Rakefile +24 -0
- data/lib/como.rb +1041 -0
- data/test/test_como.rb +344 -0
- metadata +56 -0
data/test/test_como.rb
ADDED
@@ -0,0 +1,344 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'como'
|
3
|
+
include Como
|
4
|
+
require 'stringio'
|
5
|
+
|
6
|
+
|
7
|
+
class ComoTest < Test::Unit::TestCase
|
8
|
+
|
9
|
+
def reset_state( args )
|
10
|
+
Spec.setArgv( args )
|
11
|
+
Opt.each do |i|
|
12
|
+
i.given = false
|
13
|
+
end
|
14
|
+
Spec.check
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_sanity
|
18
|
+
|
19
|
+
Opt.reset
|
20
|
+
Spec.setArgv( %w{ -f file } )
|
21
|
+
|
22
|
+
Spec.defineCheckHelp( "cmd_opt_test", "Programmer", "2013",
|
23
|
+
[
|
24
|
+
[ :silent, "help", "-h", "Display usage info." ],
|
25
|
+
[ :single, "file", "-f", "File argument." ],
|
26
|
+
] )
|
27
|
+
|
28
|
+
assert_equal( 'file', Opt['file'].value )
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
def test_values
|
33
|
+
|
34
|
+
Opt.reset
|
35
|
+
Spec.setArgv( %w{ -f file -d --o1 -o4 1 2 3 -o5 -o2 o2 rest } )
|
36
|
+
|
37
|
+
Spec.defineCheckHelp( "como_fulltest", "Programmer", "2013",
|
38
|
+
[
|
39
|
+
[ :silent, "help", "-h", "Display usage info." ],
|
40
|
+
[ :single, "file", "-f", "File argument." ],
|
41
|
+
[ :switch, "o1", "-o1", "o1" ],
|
42
|
+
[ :opt_single, "o2", "-o2", "o2" ],
|
43
|
+
[ :opt_single, "o3", "-o3", "o3" ],
|
44
|
+
[ :opt_multi, "o4", "-o4", "o4" ],
|
45
|
+
[ :opt_any, "o5", "-o5", "o5" ],
|
46
|
+
[ :switch, "debug", "-d", "Enable debugging." ],
|
47
|
+
[ :default, "rest", nil, "Default options." ],
|
48
|
+
] )
|
49
|
+
|
50
|
+
assert_equal( 'file', Opt['file'].value )
|
51
|
+
assert_equal( true, Opt['debug'].given )
|
52
|
+
assert_equal( true, Opt['o1'].given )
|
53
|
+
assert_equal( true, Opt['o2'].given )
|
54
|
+
assert_equal( 'o2', Opt['o2'].value )
|
55
|
+
assert_equal( false, Opt['o3'].given )
|
56
|
+
assert_equal( true, Opt['o4'].given )
|
57
|
+
assert_equal( %w{1 2 3}, Opt['o4'].value )
|
58
|
+
assert_equal( true, Opt['o5'].given )
|
59
|
+
assert_equal( 1, Opt[nil].value.length )
|
60
|
+
assert_equal( 'rest', Opt[nil].value[0] )
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
def test_rules
|
65
|
+
Opt.reset
|
66
|
+
Spec.setArgv( %w{ -o1 } )
|
67
|
+
|
68
|
+
Spec.defineCheckHelp( "como_fulltest", "Programmer", "2013",
|
69
|
+
[
|
70
|
+
[ :silent, "help", "-h", "Display usage info." ],
|
71
|
+
[ :switch, "o1", "-o1", "o1" ],
|
72
|
+
[ :switch, "o2", "-o2", "o2" ],
|
73
|
+
[ :switch, "o3", "-o3", "o3" ],
|
74
|
+
[ :switch, "o4", "-o4", "o4" ],
|
75
|
+
] )
|
76
|
+
|
77
|
+
# all
|
78
|
+
reset_state( %w{ -o1 -o2 -o3} )
|
79
|
+
ret = Opt.checkRule do
|
80
|
+
all( 'o1', 'o2', 'o3' )
|
81
|
+
end
|
82
|
+
assert_equal( true, ret )
|
83
|
+
|
84
|
+
reset_state( %w{ -o1 -o2 } )
|
85
|
+
ret = Opt.checkRule do
|
86
|
+
all( 'o1', 'o3' )
|
87
|
+
end
|
88
|
+
assert_equal( false, ret )
|
89
|
+
|
90
|
+
# one
|
91
|
+
reset_state( %w{ -o1 } )
|
92
|
+
ret = Opt.checkRule do
|
93
|
+
one( 'o1', 'o2' )
|
94
|
+
end
|
95
|
+
assert_equal( true, ret )
|
96
|
+
|
97
|
+
reset_state( %w{ -o1 -o2 } )
|
98
|
+
ret = Opt.checkRule do
|
99
|
+
one( 'o1', 'o2' )
|
100
|
+
end
|
101
|
+
assert_equal( false, ret )
|
102
|
+
|
103
|
+
# any
|
104
|
+
reset_state( %w{ --o2 } )
|
105
|
+
ret = Opt.checkRule do
|
106
|
+
any( 'o1', 'o2' )
|
107
|
+
end
|
108
|
+
assert_equal( true, ret )
|
109
|
+
|
110
|
+
reset_state( %w{ -o3 } )
|
111
|
+
ret = Opt.checkRule do
|
112
|
+
one( 'o1', 'o2' )
|
113
|
+
end
|
114
|
+
assert_equal( false, ret )
|
115
|
+
|
116
|
+
# none
|
117
|
+
reset_state( %w{ } )
|
118
|
+
ret = Opt.checkRule do
|
119
|
+
none
|
120
|
+
end
|
121
|
+
assert_equal( true, ret )
|
122
|
+
|
123
|
+
reset_state( %w{ -o3 } )
|
124
|
+
ret = Opt.checkRule do
|
125
|
+
none
|
126
|
+
end
|
127
|
+
assert_equal( false, ret )
|
128
|
+
|
129
|
+
# incr
|
130
|
+
reset_state( %w{ -o1 -o2 -o3} )
|
131
|
+
ret = Opt.checkRule do
|
132
|
+
incr( 'o1', 'o2', 'o3' )
|
133
|
+
end
|
134
|
+
assert_equal( true, ret )
|
135
|
+
|
136
|
+
reset_state( %w{ -o1 -o2} )
|
137
|
+
ret = Opt.checkRule do
|
138
|
+
incr( 'o1', 'o2', 'o3' )
|
139
|
+
end
|
140
|
+
assert_equal( true, ret )
|
141
|
+
|
142
|
+
reset_state( %w{ -o1 -o3} )
|
143
|
+
ret = Opt.checkRule do
|
144
|
+
incr( 'o1', 'o2', 'o3' )
|
145
|
+
end
|
146
|
+
assert_equal( false, ret )
|
147
|
+
|
148
|
+
# follow
|
149
|
+
reset_state( %w{ -o1 -o2 -o3} )
|
150
|
+
ret = Opt.checkRule do
|
151
|
+
follow( 'o1', 'o2', 'o3' )
|
152
|
+
end
|
153
|
+
assert_equal( true, ret )
|
154
|
+
|
155
|
+
reset_state( %w{ -o1 -o3 -o2} )
|
156
|
+
ret = Opt.checkRule do
|
157
|
+
follow( 'o1', 'o2', 'o3' )
|
158
|
+
end
|
159
|
+
assert_equal( true, ret )
|
160
|
+
|
161
|
+
reset_state( %w{ -o2 -o3} )
|
162
|
+
ret = Opt.checkRule do
|
163
|
+
follow( 'o1', 'o2', 'o3' )
|
164
|
+
end
|
165
|
+
assert_equal( false, ret )
|
166
|
+
|
167
|
+
reset_state( %w{-o1 -o3} )
|
168
|
+
ret = Opt.checkRule do
|
169
|
+
follow( 'o1', 'o2', 'o3' )
|
170
|
+
end
|
171
|
+
assert_equal( false, ret )
|
172
|
+
|
173
|
+
# in combination
|
174
|
+
reset_state( %w{-o2} )
|
175
|
+
ret = Opt.checkRule do
|
176
|
+
one(
|
177
|
+
one( 'o1', 'o2' ),
|
178
|
+
none
|
179
|
+
)
|
180
|
+
end
|
181
|
+
assert_equal( true, ret )
|
182
|
+
|
183
|
+
reset_state( %w{-o2 -o3} )
|
184
|
+
ret = Opt.checkRule do
|
185
|
+
all(
|
186
|
+
one( 'o1', 'o2' ),
|
187
|
+
'o3'
|
188
|
+
)
|
189
|
+
end
|
190
|
+
assert_equal( true, ret )
|
191
|
+
|
192
|
+
|
193
|
+
reset_state( %w{-o2 -o3 -o4} )
|
194
|
+
ret = Opt.checkRule do
|
195
|
+
all(
|
196
|
+
one( 'o1', 'o2' ),
|
197
|
+
'o3',
|
198
|
+
incr( 'o3', 'o4' )
|
199
|
+
)
|
200
|
+
end
|
201
|
+
assert_equal( true, ret )
|
202
|
+
|
203
|
+
|
204
|
+
reset_state( %w{-o3 -o4} )
|
205
|
+
ret = Opt.checkRule do
|
206
|
+
all(
|
207
|
+
one( 'o1', 'o2' ),
|
208
|
+
'o3',
|
209
|
+
incr( 'o3', 'o4' )
|
210
|
+
)
|
211
|
+
end
|
212
|
+
assert_equal( false, ret )
|
213
|
+
|
214
|
+
|
215
|
+
end
|
216
|
+
|
217
|
+
|
218
|
+
def test_external
|
219
|
+
Opt.reset
|
220
|
+
Spec.setArgv( %w{ -f file -- other_program -f other_file } )
|
221
|
+
|
222
|
+
Spec.defineCheckHelp( "cmd_opt_test", "Programmer", "2013",
|
223
|
+
[
|
224
|
+
[ :silent, "help", "-h", "Display usage info." ],
|
225
|
+
[ :single, "file", "-f", "File argument." ],
|
226
|
+
] )
|
227
|
+
|
228
|
+
assert_equal( 'file', Opt['file'].value )
|
229
|
+
assert_equal( %w{other_program -f other_file}, Opt.external )
|
230
|
+
end
|
231
|
+
|
232
|
+
|
233
|
+
def test_help
|
234
|
+
|
235
|
+
Opt.reset
|
236
|
+
Spec.setArgv( %w{ -h } )
|
237
|
+
Opt.setIo( StringIO.new )
|
238
|
+
|
239
|
+
Spec.defineCheckHelp( "cmd_opt_test", "Programmer", "2013",
|
240
|
+
[
|
241
|
+
[ :silent, "help", "-h", "Display usage info." ],
|
242
|
+
[ :single, "file", "-f", "File argument." ],
|
243
|
+
[ :opt_any, "list", "-l", "List argument." ],
|
244
|
+
], { :help_exit => false } )
|
245
|
+
|
246
|
+
help = "
|
247
|
+
|
248
|
+
Usage:
|
249
|
+
cmd_opt_test -f <file> [-l <list>*]
|
250
|
+
|
251
|
+
-f File argument.
|
252
|
+
-l List argument.
|
253
|
+
|
254
|
+
|
255
|
+
Copyright (c) 2013 by Programmer
|
256
|
+
|
257
|
+
"
|
258
|
+
|
259
|
+
assert_equal( help, Opt.getIo.string )
|
260
|
+
end
|
261
|
+
|
262
|
+
|
263
|
+
def test_missing
|
264
|
+
|
265
|
+
Opt.reset
|
266
|
+
Spec.setArgv( %w{ -l some args } )
|
267
|
+
Opt.setIo( StringIO.new )
|
268
|
+
|
269
|
+
Spec.defineCheckHelp( "cmd_opt_test", "Programmer", "2013",
|
270
|
+
[
|
271
|
+
[ :silent, "help", "-h", "Display usage info." ],
|
272
|
+
[ :single, "file", "-f", "File argument." ],
|
273
|
+
[ :opt_any, "list", "-l", "List argument." ],
|
274
|
+
], { :error_exit => false } )
|
275
|
+
|
276
|
+
help = "
|
277
|
+
cmd_opt_test error: Option \"-f\" missing...
|
278
|
+
|
279
|
+
|
280
|
+
Usage:
|
281
|
+
cmd_opt_test -f <file> [-l <list>*]
|
282
|
+
|
283
|
+
-f File argument.
|
284
|
+
-l List argument.
|
285
|
+
|
286
|
+
|
287
|
+
Copyright (c) 2013 by Programmer
|
288
|
+
|
289
|
+
"
|
290
|
+
|
291
|
+
assert_equal( help, Opt.getIo.string )
|
292
|
+
|
293
|
+
end
|
294
|
+
|
295
|
+
|
296
|
+
def test_invalid_rule
|
297
|
+
|
298
|
+
Opt.reset
|
299
|
+
Spec.setArgv( %w{ -o1 } )
|
300
|
+
Opt.setIo( StringIO.new )
|
301
|
+
|
302
|
+
Spec.defineCheckHelp( "como_fulltest", "Programmer", "2013",
|
303
|
+
[
|
304
|
+
[ :silent, "help", "-h", "Display usage info." ],
|
305
|
+
[ :switch, "o1", "-o1", "o1" ],
|
306
|
+
[ :switch, "o2", "-o2", "o2" ],
|
307
|
+
[ :switch, "o3", "-o3", "o3" ],
|
308
|
+
[ :switch, "o4", "-o4", "o4" ],
|
309
|
+
], { :error_exit => false } )
|
310
|
+
|
311
|
+
# all
|
312
|
+
reset_state( %w{ -o1 -o2 } )
|
313
|
+
ret = Spec.checkRule do
|
314
|
+
all( 'o1', 'o2', 'o3' )
|
315
|
+
end
|
316
|
+
|
317
|
+
help = "
|
318
|
+
como_fulltest error: Option combination mismatch!
|
319
|
+
|
320
|
+
Option combination rules:
|
321
|
+
|
322
|
+
|--# All of:
|
323
|
+
| |--<o1>
|
324
|
+
| |--<o2>
|
325
|
+
| |--<o3>
|
326
|
+
|
327
|
+
|
328
|
+
Usage:
|
329
|
+
como_fulltest [-o1] [-o2] [-o3] [-o4]
|
330
|
+
|
331
|
+
-o1 o1
|
332
|
+
-o2 o2
|
333
|
+
-o3 o3
|
334
|
+
-o4 o4
|
335
|
+
|
336
|
+
|
337
|
+
Copyright (c) 2013 by Programmer
|
338
|
+
|
339
|
+
"
|
340
|
+
|
341
|
+
assert_equal( help, Opt.getIo.string )
|
342
|
+
|
343
|
+
end
|
344
|
+
end
|
metadata
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: como
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Tero Isannainen
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-10-13 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Como provides low manifest command line option parsing and deployment.
|
15
|
+
The command line options are described in compact table format and option values
|
16
|
+
are stored to conveniently named properties. Como provides the command usage information
|
17
|
+
based on the option table (plus program info) automatically. Como supports also
|
18
|
+
checking for option combinations using a simple DSL.
|
19
|
+
email: tero.isannainen@gmail.com
|
20
|
+
executables: []
|
21
|
+
extensions: []
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.rdoc
|
24
|
+
files:
|
25
|
+
- README.rdoc
|
26
|
+
- LICENSE
|
27
|
+
- Rakefile
|
28
|
+
- lib/como.rb
|
29
|
+
- test/test_como.rb
|
30
|
+
homepage:
|
31
|
+
licenses:
|
32
|
+
- Ruby
|
33
|
+
post_install_message: Check README...
|
34
|
+
rdoc_options: []
|
35
|
+
require_paths:
|
36
|
+
- lib
|
37
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ! '>='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 1.9.3
|
43
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ! '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
requirements: []
|
50
|
+
rubyforge_project:
|
51
|
+
rubygems_version: 1.8.23
|
52
|
+
signing_key:
|
53
|
+
specification_version: 3
|
54
|
+
summary: Compact command line option parser utility.
|
55
|
+
test_files: []
|
56
|
+
has_rdoc:
|