main 2.3.0 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/README +6 -0
  2. data/a.rb +6 -6
  3. data/lib/main/base.rb +8 -4
  4. data/lib/main/parameter.rb +17 -1
  5. metadata +2 -2
data/README CHANGED
@@ -370,6 +370,12 @@ DOCS
370
370
  API section below
371
371
 
372
372
  HISTORY
373
+ 2.4.0
374
+ - fixed bug where 'abort("message")' would print "message" twice on exit
375
+ if running under a nested mode.
376
+
377
+ - allowed parameters to be overridden completely in subclasses (modes)
378
+
373
379
  2.3.0
374
380
  - re-worked Main.new such that client code may define an #initialize
375
381
  methods and the class will continue to work. that is to say it's fine
data/a.rb CHANGED
@@ -1,17 +1,17 @@
1
1
  require 'main'
2
2
 
3
3
  Main {
4
+ option 'bar'
4
5
 
5
6
  mode 'foo' do
7
+ option('bar'){ required }
8
+
6
9
  def run
7
- p mode
8
- p @a
10
+ p params
9
11
  end
10
12
  end
11
13
 
12
- def initialize
13
- @a = 42
14
+ def run
15
+ p params
14
16
  end
15
-
16
- run(){ p @a; p @argv; p @env; }
17
17
  }
@@ -6,12 +6,12 @@ module Main
6
6
 
7
7
  class_eval do
8
8
  def run *a, &b
9
+ argv.push "--#{ argv.shift }" if argv.first == 'help'
10
+ return mode_run! if mode_given?
11
+
9
12
  status =
10
13
  catch :exit do
11
14
  begin
12
- argv.push "--#{ argv.shift }" if argv.first == 'help'
13
-
14
- return mode_run! if mode_given?
15
15
 
16
16
  parse_parameters
17
17
 
@@ -139,7 +139,7 @@ module Main
139
139
 
140
140
  module DSL
141
141
  def parameter *a, &b
142
- parameters << Parameter.new(*a, &b)
142
+ (parameters << Parameter.create(:parameter, *a, &b)).last
143
143
  end
144
144
 
145
145
  def option *a, &b
@@ -354,6 +354,10 @@ module Main
354
354
  exit(status)
355
355
  end
356
356
 
357
+ def abort message = 'exit'
358
+ raise SystemExit.new(message)
359
+ end
360
+
357
361
  def handle_exception e
358
362
  if e.respond_to?(:error_handler_before)
359
363
  fcall(e, :error_handler_before, self)
@@ -29,7 +29,7 @@ module Main
29
29
  end
30
30
  end
31
31
 
32
- Types = []
32
+ Types = [ Parameter ]
33
33
  def inherited other
34
34
  Types << other
35
35
  end
@@ -443,6 +443,22 @@ module Main
443
443
  end
444
444
  end
445
445
  end
446
+
447
+ def delete name, *names
448
+ name, *names = name.names if Parameter === name
449
+ names = Cast.list_of_string name, *names
450
+ keep = []
451
+ each do |param|
452
+ common = Cast.list_of_string(param.names) & names
453
+ keep << param if common.empty?
454
+ end
455
+ replace keep
456
+ end
457
+
458
+ def << *a
459
+ delete *a
460
+ super
461
+ end
446
462
  end
447
463
 
448
464
  class DSL
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: main
5
5
  version: !ruby/object:Gem::Version
6
- version: 2.3.0
7
- date: 2007-10-27 00:00:00 -06:00
6
+ version: 2.4.0
7
+ date: 2007-11-02 00:00:00 -06:00
8
8
  summary: main
9
9
  require_paths:
10
10
  - lib