main 2.8.2 → 2.8.3

Sign up to get free protection for your applications and to get access to all the features.
data/TODO CHANGED
@@ -1,4 +1,14 @@
1
1
 
2
+ * support pathname casts
3
+ * support uri casts
4
+ * support filename casts
5
+ * support directory costs
6
+ * support io cast '-' (:input, :output)
7
+
8
+ * fix weird super bug jeremy found
9
+
10
+ * figure out how to support '-' ??
11
+
2
12
  * clean up warnings under 'ruby -d'
3
13
  * error reporting weird for some errors
4
14
 
data/install.rb CHANGED
File without changes
@@ -2,7 +2,7 @@ module Main
2
2
  #
3
3
  # top level constants
4
4
  #
5
- Main::VERSION = '2.8.2' unless
5
+ Main::VERSION = '2.8.3' unless
6
6
  defined? Main::VERSION
7
7
  def self.version() Main::VERSION end
8
8
 
@@ -402,7 +402,7 @@ module Main
402
402
  def parse_parameters
403
403
  pre_parse_parameters
404
404
 
405
- self.class.parameters.parse @argv, @env
405
+ self.class.parameters.parse self
406
406
  @params = Parameter::Table.new
407
407
  self.class.parameters.each{|p| @params[p.name.to_s] = p}
408
408
 
@@ -305,21 +305,36 @@ puts
305
305
  end
306
306
 
307
307
  class List < ::Array
308
- def parse argv, env
308
+ fattr :main
309
+ fattr :argv
310
+ fattr :env
311
+
312
+ def parse main
313
+ @main, @argv, @env = main, main.argv, main.env
314
+
309
315
  ignore, stop = [], argv.index('--')
316
+
310
317
  if stop
311
318
  ignore = argv[stop .. -1]
312
319
  (argv.size - stop).times{ argv.pop }
313
320
  end
321
+
314
322
  parse_options argv
323
+
315
324
  return 'help' if detect{|p| p.name.to_s == 'help' and p.given?}
325
+
316
326
  parse_keywords argv
317
327
  parse_arguments argv
318
328
  parse_environment env
329
+
319
330
  defaults!
320
331
  validate!
332
+
321
333
  argv.push *ignore[1 .. -1] unless ignore.empty?
322
- self
334
+
335
+ return self
336
+ ensure
337
+ @main, @argv, @env = nil
323
338
  end
324
339
 
325
340
  def parse_options argv, params = nil
@@ -463,7 +478,7 @@ puts
463
478
  each do |p|
464
479
  if(p.defaults? and (not p.given?))
465
480
  p.defaults.each do |default|
466
- p.values << default # so as NOT to set 'given?'
481
+ p.values << (default.respond_to?('to_proc') ? main.instance_eval(&default) : default) # so as NOT to set 'given?'
467
482
  end
468
483
  end
469
484
  end
@@ -624,19 +639,19 @@ puts
624
639
  end
625
640
  alias_method 'desc', 'description'
626
641
 
627
- def default value, *values
628
- param.defaults.push value
629
- param.defaults.push *values
630
- param.defaults
631
- end
632
- def defaults?
633
- param.defaults?
634
- end
635
- def defaults value, *values
636
- param.defaults.push value
637
- param.defaults.push *values
642
+ def default *values, &block
643
+ if block.nil? and values.empty?
644
+ raise ArgumentError, 'no default'
645
+ end
646
+ unless values.empty?
647
+ param.defaults.push *values
648
+ end
649
+ unless block.nil?
650
+ param.defaults.push block
651
+ end
638
652
  param.defaults
639
653
  end
654
+ alias_method 'defaults', 'default'
640
655
  def defaults?
641
656
  param.defaults?
642
657
  end
@@ -0,0 +1,34 @@
1
+ require 'main'
2
+
3
+ #
4
+ # ./h.rb #=> forty-two
5
+ # ./h.rb a #=> 42
6
+ # ./h.rb b #=> 42.0
7
+ #
8
+
9
+ Main {
10
+ fattr :default_for_foobar => 'forty-two'
11
+
12
+ option(:foobar) do
13
+ default{ default_for_foobar }
14
+ end
15
+
16
+ mixin :foo do
17
+ fattr :default_for_foobar => 42
18
+ end
19
+
20
+ mixin :bar do
21
+ fattr :default_for_foobar => 42.0
22
+ end
23
+
24
+
25
+ run{ p params[:foobar].value }
26
+
27
+ mode :a do
28
+ mixin :foo
29
+ end
30
+
31
+ mode :b do
32
+ mixin :bar
33
+ end
34
+ }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: main
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.8.2
4
+ version: 2.8.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ara T. Howard
@@ -9,11 +9,12 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-07-13 00:00:00 -06:00
12
+ date: 2008-10-22 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: fattr
17
+ type: :runtime
17
18
  version_requirement:
18
19
  version_requirements: !ruby/object:Gem::Requirement
19
20
  requirements:
@@ -23,6 +24,7 @@ dependencies:
23
24
  version:
24
25
  - !ruby/object:Gem::Dependency
25
26
  name: arrayfields
27
+ type: :runtime
26
28
  version_requirement:
27
29
  version_requirements: !ruby/object:Gem::Requirement
28
30
  requirements:
@@ -65,6 +67,7 @@ files:
65
67
  - samples/e.rb
66
68
  - samples/f.rb
67
69
  - samples/g.rb
70
+ - samples/h.rb
68
71
  - test
69
72
  - test/main.rb
70
73
  - TODO
@@ -90,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
93
  requirements: []
91
94
 
92
95
  rubyforge_project: codeforpeople
93
- rubygems_version: 1.0.1
96
+ rubygems_version: 1.2.0
94
97
  signing_key:
95
98
  specification_version: 2
96
99
  summary: main