main 6.3.0 → 6.4.0
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/LICENSE +1 -0
- data/README.erb +4 -4
- data/Rakefile +2 -1
- data/a.rb +14 -0
- data/lib/main/parameter.rb +53 -88
- data/lib/main/program/class_methods.rb +1 -1
- data/lib/main/program/instance_methods.rb +18 -6
- data/lib/main.rb +1 -1
- data/main.gemspec +5 -2
- data/test/main_test.rb +87 -3
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0599943ad7c254dc66a971cf4106c1681e749539715d097660c71e89d9b8296e'
|
4
|
+
data.tar.gz: d0adfd263b9f1866b34ee50d4f4f6449d71a6db03019cd5819478f177ce53a58
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 499625257c9d8abfad6748ddf2816d1273726bbbfb064c54e1df4103e14b4903df84b7756354e02b732ba613a2c67f83d5520aaa9e47958fa2cbd51cb1b79898
|
7
|
+
data.tar.gz: 439fc076475d87ceff4f632249f3728c1bf7e007d2c72d2f2c7fdf0013efe0f5fcbe3b11103c0acc726f5141286c45d8e5feaab2d94e5b279ae076f6c399bd93
|
data/LICENSE
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Ruby
|
data/README.erb
CHANGED
@@ -48,8 +48,8 @@ DESCRIPTION
|
|
48
48
|
end
|
49
49
|
}
|
50
50
|
|
51
|
-
sets up a program which requires one argument, '
|
52
|
-
command line switch, '--
|
51
|
+
sets up a program which requires one argument, 'foo', and which may accept one
|
52
|
+
command line switch, '--bar' in addition to the single option/mode which is always
|
53
53
|
accepted and handled appropriately: 'help', '--help', '-h'. for the most
|
54
54
|
part main.rb stays out of your command line namespace but insists that your
|
55
55
|
application has at least a help mode/option.
|
@@ -372,7 +372,7 @@ HISTORY
|
|
372
372
|
end
|
373
373
|
}
|
374
374
|
|
375
|
-
- added sanity check at end of paramter
|
375
|
+
- added sanity check at end of paramter construction
|
376
376
|
|
377
377
|
- improved auto usage generation when arity is used with arguments
|
378
378
|
|
@@ -627,7 +627,7 @@ HISTORY
|
|
627
627
|
|
628
628
|
initial version. this version extracts much of the functionality of alib's
|
629
629
|
(gen install alib) Alib.script main program generator and also some of jim's
|
630
|
-
freeze's excellent CommandLine::
|
630
|
+
freeze's excellent CommandLine::Application into what i hope is a simpler and
|
631
631
|
more unified interface
|
632
632
|
|
633
633
|
API
|
data/Rakefile
CHANGED
@@ -98,7 +98,7 @@ task :gemspec do
|
|
98
98
|
This.extensions = []
|
99
99
|
extensions = This.extensions
|
100
100
|
%w( Makefile configure extconf.rb ).each do |ext|
|
101
|
-
extensions << ext if File.
|
101
|
+
extensions << ext if File.exist?(ext)
|
102
102
|
end
|
103
103
|
end
|
104
104
|
extensions = [extensions].flatten.compact
|
@@ -137,6 +137,7 @@ task :gemspec do
|
|
137
137
|
spec.require_path = "lib"
|
138
138
|
|
139
139
|
spec.test_files = <%= test_files.inspect %>
|
140
|
+
spec.required_ruby_version = '>= 2.0'
|
140
141
|
|
141
142
|
<% dependencies.each do |lib_version| %>
|
142
143
|
spec.add_dependency(*<%= Array(lib_version).flatten.inspect %>)
|
data/a.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require './lib/main'
|
2
|
+
|
3
|
+
ARGV.replace %w()
|
4
|
+
Main {
|
5
|
+
option('foo', 'f'){
|
6
|
+
#required # by default options are not required, we could use 'foo=foo'
|
7
|
+
# above as a shortcut
|
8
|
+
# argument_required
|
9
|
+
}
|
10
|
+
|
11
|
+
def run
|
12
|
+
p "Did you pass --foo ? #{params['foo'].given? == true}"
|
13
|
+
end
|
14
|
+
}
|
data/lib/main/parameter.rb
CHANGED
@@ -69,7 +69,7 @@ module Main
|
|
69
69
|
fattr('defaults'){ [] }
|
70
70
|
fattr('examples'){ [] }
|
71
71
|
|
72
|
-
fattr
|
72
|
+
fattr('arity'){ 1 }
|
73
73
|
fattr 'required' => false
|
74
74
|
|
75
75
|
fattr 'error_handler_before'
|
@@ -149,7 +149,7 @@ module Main
|
|
149
149
|
end
|
150
150
|
|
151
151
|
def argument_required?
|
152
|
-
argument and
|
152
|
+
argument and
|
153
153
|
argument.to_s.downcase.to_sym == :required
|
154
154
|
end
|
155
155
|
def argument_optional?
|
@@ -160,22 +160,10 @@ module Main
|
|
160
160
|
def optional?
|
161
161
|
not required?
|
162
162
|
end
|
163
|
-
def optional= bool
|
163
|
+
def optional= bool
|
164
164
|
self.required !bool
|
165
165
|
end
|
166
166
|
|
167
|
-
=begin
|
168
|
-
def setup!
|
169
|
-
return false unless given?
|
170
|
-
adding_handlers do
|
171
|
-
check_arity
|
172
|
-
apply_casting
|
173
|
-
check_validation
|
174
|
-
end
|
175
|
-
true
|
176
|
-
end
|
177
|
-
=end
|
178
|
-
|
179
167
|
def setup!
|
180
168
|
adding_handlers do
|
181
169
|
check_arity
|
@@ -184,13 +172,18 @@ module Main
|
|
184
172
|
end
|
185
173
|
end
|
186
174
|
|
187
|
-
def check_arity
|
175
|
+
def check_arity
|
188
176
|
return true if not given? and optional?
|
189
177
|
|
178
|
+
arity = self.arity
|
190
179
|
ex = values.size == 0 ? NotGiven : Arity
|
191
180
|
|
192
181
|
(raise ex, "#{ typename })" if values.size.zero? and argument_required?) unless arity == -1
|
193
182
|
|
183
|
+
if arity >= 0 && values.size > arity
|
184
|
+
raise ex, "#{ typename } #{ values.size }/#{ arity }"
|
185
|
+
end
|
186
|
+
|
194
187
|
if arity >= 0
|
195
188
|
min = arity
|
196
189
|
sign = ''
|
@@ -203,14 +196,14 @@ module Main
|
|
203
196
|
|
204
197
|
if values.size < arity
|
205
198
|
if argument_optional?
|
206
|
-
raise ex, "#{ typename }
|
199
|
+
raise ex, "#{ typename } #{ values.size }/#{ sign }#{ arity }" if(values.size < arity and values.size > 0)
|
207
200
|
elsif argument_required? or argument_none?
|
208
|
-
raise ex, "#{ typename }
|
201
|
+
raise ex, "#{ typename } #{ values.size }/#{ sign }#{ arity }" if(values.size < arity)
|
209
202
|
end
|
210
203
|
end
|
211
204
|
end
|
212
205
|
|
213
|
-
def apply_casting
|
206
|
+
def apply_casting
|
214
207
|
if cast?
|
215
208
|
op = cast.respond_to?('call') ? cast : Cast[cast]
|
216
209
|
case op.arity
|
@@ -225,17 +218,17 @@ module Main
|
|
225
218
|
end
|
226
219
|
end
|
227
220
|
|
228
|
-
def check_validation
|
221
|
+
def check_validation
|
229
222
|
if validate?
|
230
223
|
values.each do |value|
|
231
|
-
validate[value] or
|
224
|
+
validate[value] or
|
232
225
|
raise InValid, "invalid: #{ typename }=#{ value.inspect }"
|
233
226
|
end
|
234
227
|
end
|
235
228
|
end
|
236
229
|
|
237
230
|
def add_handlers e
|
238
|
-
esc =
|
231
|
+
esc =
|
239
232
|
class << e
|
240
233
|
self
|
241
234
|
end
|
@@ -244,7 +237,7 @@ module Main
|
|
244
237
|
getter = "error_handler_#{ which }"
|
245
238
|
query = "error_handler_#{ which }?"
|
246
239
|
if send(query)
|
247
|
-
handler = send getter
|
240
|
+
handler = send getter
|
248
241
|
esc.module_eval do
|
249
242
|
define_method(getter) do |main|
|
250
243
|
main.instance_eval_block self, &handler
|
@@ -276,7 +269,7 @@ module Main
|
|
276
269
|
fattr 'synopsis' do
|
277
270
|
label = name
|
278
271
|
op = required ? "->" : "~>"
|
279
|
-
value = defaults.size > 0 ? "#{ name }=#{ defaults.join ',' }" : name
|
272
|
+
value = defaults.size > 0 ? "#{ name }=#{ defaults.join ',' }" : name
|
280
273
|
value = "#{ cast }(#{ value })" if(cast and not cast.respond_to?(:call))
|
281
274
|
"#{ label } (#{ arity } #{ op } #{ value })"
|
282
275
|
end
|
@@ -284,16 +277,16 @@ module Main
|
|
284
277
|
|
285
278
|
class Option < Parameter
|
286
279
|
fattr 'required' => false
|
287
|
-
fattr
|
280
|
+
fattr('arity'){ 1 }
|
288
281
|
|
289
282
|
fattr 'synopsis' do
|
290
283
|
long, *short = names
|
291
|
-
value = cast || name
|
292
|
-
rhs = argument ? (argument == :required ? "=#{ name }" : "=[#{ name }]") : nil
|
284
|
+
value = cast || name
|
285
|
+
rhs = argument ? (argument == :required ? "=#{ name }" : "=[#{ name }]") : nil
|
293
286
|
label = ["--#{ long }#{ rhs }", short.map{|s| "-#{ s }"}].flatten.join(", ")
|
294
287
|
unless argument_none?
|
295
288
|
op = required ? "->" : "~>"
|
296
|
-
value = defaults.size > 0 ? "#{ name }=#{ defaults.join ',' }" : name
|
289
|
+
value = defaults.size > 0 ? "#{ name }=#{ defaults.join ',' }" : name
|
297
290
|
value = "#{ cast }(#{ value })" if(cast and not cast.respond_to?(:call))
|
298
291
|
"#{ label } (#{ arity } #{ op } #{ value })"
|
299
292
|
else
|
@@ -304,24 +297,24 @@ module Main
|
|
304
297
|
|
305
298
|
class Keyword < Parameter
|
306
299
|
fattr 'required' => false
|
307
|
-
fattr 'argument' => :required
|
300
|
+
fattr 'argument' => :required
|
308
301
|
|
309
302
|
fattr 'synopsis' do
|
310
303
|
label = "#{ name }=#{ name }"
|
311
304
|
op = required ? "->" : "~>"
|
312
|
-
value = defaults.size > 0 ? "#{ name }=#{ defaults.join ',' }" : name
|
305
|
+
value = defaults.size > 0 ? "#{ name }=#{ defaults.join ',' }" : name
|
313
306
|
value = "#{ cast }(#{ value })" if(cast and not cast.respond_to?(:call))
|
314
307
|
"#{ label } (#{ arity } #{ op } #{ value })"
|
315
308
|
end
|
316
309
|
end
|
317
310
|
|
318
311
|
class Environment < Parameter
|
319
|
-
fattr 'argument' => :required
|
312
|
+
fattr 'argument' => :required
|
320
313
|
|
321
314
|
fattr 'synopsis' do
|
322
315
|
label = "env[#{ name }]=#{ name }"
|
323
316
|
op = required ? "->" : "~>"
|
324
|
-
value = defaults.size > 0 ? "#{ name }=#{ defaults.join ',' }" : name
|
317
|
+
value = defaults.size > 0 ? "#{ name }=#{ defaults.join ',' }" : name
|
325
318
|
value = "#{ cast }(#{ value })" if(cast and not cast.respond_to?(:call))
|
326
319
|
"#{ label } (#{ arity } #{ op } #{ value })"
|
327
320
|
end
|
@@ -355,7 +348,7 @@ module Main
|
|
355
348
|
defaults!
|
356
349
|
validate!
|
357
350
|
|
358
|
-
argv.push(*ignore) unless ignore.empty?
|
351
|
+
argv.push(*ignore) unless ignore.empty?
|
359
352
|
|
360
353
|
return self
|
361
354
|
ensure
|
@@ -363,7 +356,7 @@ module Main
|
|
363
356
|
end
|
364
357
|
|
365
358
|
def parse_options argv, params = nil
|
366
|
-
params ||= options
|
359
|
+
params ||= options
|
367
360
|
|
368
361
|
spec, h, s = [], {}, {}
|
369
362
|
|
@@ -377,9 +370,9 @@ module Main
|
|
377
370
|
else GetoptLong::NO_ARGUMENT
|
378
371
|
end
|
379
372
|
a = [ long, shorts, type ].flatten
|
380
|
-
spec << a
|
381
|
-
h[long] = p
|
382
|
-
s[long] = a
|
373
|
+
spec << a
|
374
|
+
h[long] = p
|
375
|
+
s[long] = a
|
383
376
|
end
|
384
377
|
|
385
378
|
begin
|
@@ -404,12 +397,6 @@ module Main
|
|
404
397
|
ex.extend Softspoken
|
405
398
|
raise ex
|
406
399
|
end
|
407
|
-
|
408
|
-
=begin
|
409
|
-
params.each do |p|
|
410
|
-
p.setup!
|
411
|
-
end
|
412
|
-
=end
|
413
400
|
end
|
414
401
|
|
415
402
|
def parse_arguments argv, params=nil
|
@@ -435,12 +422,6 @@ module Main
|
|
435
422
|
end
|
436
423
|
end
|
437
424
|
end
|
438
|
-
|
439
|
-
=begin
|
440
|
-
params.each do |p|
|
441
|
-
p.setup!
|
442
|
-
end
|
443
|
-
=end
|
444
425
|
end
|
445
426
|
|
446
427
|
def parse_keywords argv, params=nil
|
@@ -454,7 +435,7 @@ module Main
|
|
454
435
|
|
455
436
|
kre = %r/^\s*(#{ names.join '|' })\s*=/
|
456
437
|
opt = "--#{ name }"
|
457
|
-
i = -1
|
438
|
+
i = -1
|
458
439
|
|
459
440
|
argv.each_with_index do |a, idx|
|
460
441
|
i += 1
|
@@ -465,12 +446,6 @@ module Main
|
|
465
446
|
replacements[i] ||= a.gsub %r/^\s*#{ key }/, opt
|
466
447
|
next
|
467
448
|
end
|
468
|
-
=begin
|
469
|
-
abbrev = name.index(key) == 0
|
470
|
-
if abbrev
|
471
|
-
replacements[i] ||= a.gsub %r/^\s*#{ key }/, opt
|
472
|
-
end
|
473
|
-
=end
|
474
449
|
end
|
475
450
|
end
|
476
451
|
|
@@ -480,7 +455,7 @@ module Main
|
|
480
455
|
|
481
456
|
parse_options argv, params
|
482
457
|
end
|
483
|
-
|
458
|
+
|
484
459
|
def parse_environment env, params=nil
|
485
460
|
params ||= select{|p| p.type == :environment}
|
486
461
|
|
@@ -491,17 +466,11 @@ module Main
|
|
491
466
|
next unless value
|
492
467
|
p.add_value value
|
493
468
|
end
|
494
|
-
|
495
|
-
=begin
|
496
|
-
params.each do |p|
|
497
|
-
p.setup!
|
498
|
-
end
|
499
|
-
=end
|
500
469
|
end
|
501
470
|
|
502
471
|
def defaults!
|
503
472
|
each do |p|
|
504
|
-
if(p.defaults? and (not p.given?))
|
473
|
+
if(p.defaults? and (not p.given?))
|
505
474
|
p.defaults.each do |default|
|
506
475
|
p.values << (default.respond_to?('to_proc') ? main.instance_eval(&default) : default) # so as NOT to set 'given?'
|
507
476
|
end
|
@@ -511,22 +480,18 @@ module Main
|
|
511
480
|
|
512
481
|
def validate!
|
513
482
|
each do |p|
|
514
|
-
#p.adding_handlers do
|
515
|
-
#next if p.arity == -1
|
516
|
-
#raise NotGiven, "#{ p.typename } not given" if(p.required? and (not p.given?))
|
517
|
-
#end
|
518
483
|
p.setup!
|
519
484
|
end
|
520
485
|
end
|
521
486
|
|
522
|
-
[:parameter, :option, :argument, :keyword, :environment].each do |m|
|
487
|
+
[:parameter, :option, :argument, :keyword, :environment].each do |m|
|
523
488
|
define_method("#{ m }s"){ select{|p| p.type == m or m == :parameter} }
|
524
489
|
|
525
490
|
define_method("has_#{ m }?") do |name, *names|
|
526
491
|
catch :has do
|
527
492
|
names = Cast.list_of_string name, *names
|
528
493
|
send("#{ m }s").each do |param|
|
529
|
-
common = Cast.list_of_string(param.names) & names
|
494
|
+
common = Cast.list_of_string(param.names) & names
|
530
495
|
throw :has, true unless common.empty?
|
531
496
|
end
|
532
497
|
false
|
@@ -539,7 +504,7 @@ module Main
|
|
539
504
|
names = Cast.list_of_string name, *names
|
540
505
|
keep = []
|
541
506
|
each do |param|
|
542
|
-
common = Cast.list_of_string(param.names) & names
|
507
|
+
common = Cast.list_of_string(param.names) & names
|
543
508
|
keep << param if common.empty?
|
544
509
|
end
|
545
510
|
replace keep
|
@@ -603,18 +568,18 @@ module Main
|
|
603
568
|
param.type?
|
604
569
|
end
|
605
570
|
|
606
|
-
def synopsis *arg
|
571
|
+
def synopsis *arg
|
607
572
|
arg.size == 0 ? param.synopsis : (param.synopsis arg.first)
|
608
573
|
end
|
609
574
|
|
610
|
-
def argument arg
|
611
|
-
param.argument arg
|
575
|
+
def argument arg
|
576
|
+
param.argument arg
|
612
577
|
end
|
613
578
|
def argument_required bool = true
|
614
579
|
if bool
|
615
580
|
param.argument :required
|
616
581
|
else
|
617
|
-
param.argument false
|
582
|
+
param.argument false
|
618
583
|
end
|
619
584
|
end
|
620
585
|
def argument_required?
|
@@ -625,46 +590,46 @@ module Main
|
|
625
590
|
if bool
|
626
591
|
param.argument :optional
|
627
592
|
else
|
628
|
-
param.argument false
|
593
|
+
param.argument false
|
629
594
|
end
|
630
595
|
end
|
631
596
|
def argument_optional?
|
632
597
|
param.argument_optional?
|
633
598
|
end
|
634
599
|
|
635
|
-
def required bool = true
|
636
|
-
param.required = bool
|
600
|
+
def required bool = true
|
601
|
+
param.required = bool
|
637
602
|
end
|
638
603
|
def required?
|
639
604
|
param.required?
|
640
605
|
end
|
641
606
|
|
642
|
-
def optional bool = true
|
643
|
-
if bool
|
644
|
-
param.required !bool
|
607
|
+
def optional bool = true
|
608
|
+
if bool
|
609
|
+
param.required !bool
|
645
610
|
else
|
646
|
-
param.required bool
|
611
|
+
param.required bool
|
647
612
|
end
|
648
613
|
end
|
649
614
|
def optional?
|
650
615
|
param.optional?
|
651
616
|
end
|
652
617
|
|
653
|
-
def cast sym=nil, &b
|
654
|
-
param.cast = sym || b
|
618
|
+
def cast sym=nil, &b
|
619
|
+
param.cast = sym || b
|
655
620
|
end
|
656
621
|
def cast?
|
657
622
|
param.cast?
|
658
623
|
end
|
659
624
|
|
660
|
-
def validate sym=nil, &b
|
661
|
-
param.validate = sym || b
|
625
|
+
def validate sym=nil, &b
|
626
|
+
param.validate = sym || b
|
662
627
|
end
|
663
628
|
def validate?
|
664
629
|
param.validate?
|
665
630
|
end
|
666
631
|
|
667
|
-
def description s
|
632
|
+
def description s
|
668
633
|
param.description = s.to_s
|
669
634
|
end
|
670
635
|
def description?
|
@@ -725,7 +690,7 @@ module Main
|
|
725
690
|
def [] *a, &b
|
726
691
|
p = super
|
727
692
|
ensure
|
728
|
-
raise NoneSuch, a.join(',') unless p
|
693
|
+
raise NoneSuch, a.join(',') unless p
|
729
694
|
end
|
730
695
|
end
|
731
696
|
end
|
@@ -15,13 +15,25 @@ module Main
|
|
15
15
|
fattr('params'){ Parameter::Table.new }
|
16
16
|
fattr('finalizers'){ [] }
|
17
17
|
|
18
|
-
%w(
|
18
|
+
%w(
|
19
19
|
program name synopsis description author version
|
20
|
-
exit_status
|
20
|
+
exit_status
|
21
21
|
logger_level
|
22
22
|
usage
|
23
23
|
).each{|a| fattr(a){ self.class.send a}}
|
24
24
|
|
25
|
+
%w( success failure warn warning ).each do |status|
|
26
|
+
module_eval <<-____, __FILE__, __LINE__
|
27
|
+
def exit_#{ status }
|
28
|
+
self.class.send(:exit_#{ status })
|
29
|
+
end
|
30
|
+
|
31
|
+
def exit_#{ status }!
|
32
|
+
throw :exit, self.class.send(:exit_#{ status })
|
33
|
+
end
|
34
|
+
____
|
35
|
+
end
|
36
|
+
|
25
37
|
alias_method 'status', 'exit_status'
|
26
38
|
alias_method 'status=', 'exit_status='
|
27
39
|
|
@@ -32,11 +44,11 @@ module Main
|
|
32
44
|
end
|
33
45
|
|
34
46
|
%w( debug info warn fatal error ).each do |m|
|
35
|
-
module_eval <<-
|
47
|
+
module_eval <<-____, __FILE__, __LINE__
|
36
48
|
def #{ m }(*a, &b)
|
37
49
|
logger.#{ m }(*a, &b)
|
38
50
|
end
|
39
|
-
|
51
|
+
____
|
40
52
|
end
|
41
53
|
|
42
54
|
def pre_initialize() :hook end
|
@@ -254,11 +266,11 @@ module Main
|
|
254
266
|
end
|
255
267
|
|
256
268
|
%w[ before instead after ].each do |which|
|
257
|
-
module_eval <<-
|
269
|
+
module_eval <<-____, __FILE__, __LINE__
|
258
270
|
def error_handler_#{ which }(*argv, &block)
|
259
271
|
block.call(*argv)
|
260
272
|
end
|
261
|
-
|
273
|
+
____
|
262
274
|
end
|
263
275
|
|
264
276
|
def instance_eval_block(*argv, &block)
|
data/lib/main.rb
CHANGED
data/main.gemspec
CHANGED
@@ -3,17 +3,19 @@
|
|
3
3
|
|
4
4
|
Gem::Specification::new do |spec|
|
5
5
|
spec.name = "main"
|
6
|
-
spec.version = "6.
|
6
|
+
spec.version = "6.4.0"
|
7
7
|
spec.platform = Gem::Platform::RUBY
|
8
8
|
spec.summary = "main"
|
9
9
|
spec.description = "a class factory and dsl for generating command line programs real quick"
|
10
10
|
spec.license = "Ruby"
|
11
11
|
|
12
12
|
spec.files =
|
13
|
-
["
|
13
|
+
["LICENSE",
|
14
|
+
"README",
|
14
15
|
"README.erb",
|
15
16
|
"Rakefile",
|
16
17
|
"TODO",
|
18
|
+
"a.rb",
|
17
19
|
"lib",
|
18
20
|
"lib/main",
|
19
21
|
"lib/main.rb",
|
@@ -53,6 +55,7 @@ Gem::Specification::new do |spec|
|
|
53
55
|
spec.require_path = "lib"
|
54
56
|
|
55
57
|
spec.test_files = nil
|
58
|
+
spec.required_ruby_version = '>= 2.0'
|
56
59
|
|
57
60
|
|
58
61
|
spec.add_dependency(*["chronic", "~> 0.10", ">= 0.10.2"])
|
data/test/main_test.rb
CHANGED
@@ -40,7 +40,6 @@ class T < Test::Unit::TestCase
|
|
40
40
|
main
|
41
41
|
end
|
42
42
|
|
43
|
-
|
44
43
|
# basic test
|
45
44
|
#
|
46
45
|
def test_0000
|
@@ -57,9 +56,8 @@ class T < Test::Unit::TestCase
|
|
57
56
|
define_method(:run){ x = 42 }
|
58
57
|
}
|
59
58
|
}
|
60
|
-
assert_equal 42, x
|
59
|
+
assert_equal 42, x
|
61
60
|
end
|
62
|
-
|
63
61
|
# exit status
|
64
62
|
#
|
65
63
|
def test_0020
|
@@ -992,6 +990,92 @@ class T < Test::Unit::TestCase
|
|
992
990
|
end
|
993
991
|
end
|
994
992
|
end
|
993
|
+
def test_0930
|
994
|
+
argv = ['\1', '[' , ']', '\\']
|
995
|
+
assert_nothing_raised{
|
996
|
+
main(argv.dup){
|
997
|
+
argument('args') { arity(-1) }
|
998
|
+
define_method('run'){ 42 }
|
999
|
+
}.run
|
1000
|
+
}
|
1001
|
+
end
|
1002
|
+
def test_0940
|
1003
|
+
%w[ exit_failure! exit_success! exit_warn! ].each do |exit_method|
|
1004
|
+
assert_nothing_raised{
|
1005
|
+
result = 42
|
1006
|
+
|
1007
|
+
main(){
|
1008
|
+
define_method :run do
|
1009
|
+
send(exit_method)
|
1010
|
+
result = :boom
|
1011
|
+
end
|
1012
|
+
}.run
|
1013
|
+
|
1014
|
+
assert result == 42
|
1015
|
+
}
|
1016
|
+
end
|
1017
|
+
end
|
1018
|
+
def test_0950
|
1019
|
+
assert_nothing_raised{
|
1020
|
+
error = nil
|
1021
|
+
|
1022
|
+
main{
|
1023
|
+
define_method(:run) do
|
1024
|
+
begin
|
1025
|
+
params[:missing]
|
1026
|
+
rescue Main::Parameter::NoneSuch => e
|
1027
|
+
error = e
|
1028
|
+
end
|
1029
|
+
end
|
1030
|
+
}.run
|
1031
|
+
|
1032
|
+
assert error.message =~ /missing/
|
1033
|
+
}
|
1034
|
+
end
|
1035
|
+
def test_0960
|
1036
|
+
argv = ['--foo', '--foo']
|
1037
|
+
error = nil
|
1038
|
+
|
1039
|
+
assert_nothing_raised{
|
1040
|
+
begin
|
1041
|
+
main(argv){
|
1042
|
+
option(:foo)
|
1043
|
+
|
1044
|
+
define_method(:run) do
|
1045
|
+
params[:foo]
|
1046
|
+
end
|
1047
|
+
}.run
|
1048
|
+
rescue => e
|
1049
|
+
error = e
|
1050
|
+
end
|
1051
|
+
}
|
1052
|
+
|
1053
|
+
assert error
|
1054
|
+
assert error.message =~ /foo/
|
1055
|
+
end
|
1056
|
+
def test_0970
|
1057
|
+
argv = []
|
1058
|
+
error = nil
|
1059
|
+
|
1060
|
+
assert_nothing_raised{
|
1061
|
+
begin
|
1062
|
+
main(argv){
|
1063
|
+
option('foo', 'f'){
|
1064
|
+
required
|
1065
|
+
}
|
1066
|
+
|
1067
|
+
define_method(:run) do
|
1068
|
+
params[:foo]
|
1069
|
+
end
|
1070
|
+
}.run
|
1071
|
+
rescue => e
|
1072
|
+
error = e
|
1073
|
+
end
|
1074
|
+
}
|
1075
|
+
|
1076
|
+
assert error
|
1077
|
+
assert error.message =~ /foo/
|
1078
|
+
end
|
995
1079
|
end
|
996
1080
|
|
997
1081
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: main
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.
|
4
|
+
version: 6.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ara T. Howard
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-04-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: chronic
|
@@ -96,10 +96,12 @@ executables: []
|
|
96
96
|
extensions: []
|
97
97
|
extra_rdoc_files: []
|
98
98
|
files:
|
99
|
+
- LICENSE
|
99
100
|
- README
|
100
101
|
- README.erb
|
101
102
|
- Rakefile
|
102
103
|
- TODO
|
104
|
+
- a.rb
|
103
105
|
- lib/main.rb
|
104
106
|
- lib/main/cast.rb
|
105
107
|
- lib/main/daemon.rb
|
@@ -140,14 +142,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
140
142
|
requirements:
|
141
143
|
- - ">="
|
142
144
|
- !ruby/object:Gem::Version
|
143
|
-
version: '0'
|
145
|
+
version: '2.0'
|
144
146
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
147
|
requirements:
|
146
148
|
- - ">="
|
147
149
|
- !ruby/object:Gem::Version
|
148
150
|
version: '0'
|
149
151
|
requirements: []
|
150
|
-
rubygems_version: 3.
|
152
|
+
rubygems_version: 3.5.16
|
151
153
|
signing_key:
|
152
154
|
specification_version: 4
|
153
155
|
summary: main
|