main 4.2.0 → 4.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1 @@
1
+ same as Ruby's
data/a.rb CHANGED
@@ -1,14 +1,6 @@
1
1
  require 'main'
2
2
 
3
3
  Main {
4
- mode( :foo ) {
5
- argument( :bar ) {
6
- required
7
- default 42
8
- }
9
- run {
10
- puts "Doing something with #{params['bar'].value}"
11
- }
12
- }
4
+ argument('zero_or_more'){ arity(-1) }
5
+ run{ p params }
13
6
  }
14
-
@@ -2,7 +2,7 @@ module Main
2
2
  #
3
3
  # top level constants
4
4
  #
5
- Main::VERSION = '4.2.0' unless
5
+ Main::VERSION = '4.3.0' unless
6
6
  defined? Main::VERSION
7
7
  def self.version() Main::VERSION end
8
8
 
@@ -19,6 +19,9 @@ module Main
19
19
  require 'logger'
20
20
  require 'enumerator'
21
21
  require 'set'
22
+ require 'uri'
23
+ require 'time'
24
+ require 'date'
22
25
  #
23
26
  # use gems to pick up dependancies
24
27
  #
@@ -28,6 +31,12 @@ module Main
28
31
  42
29
32
  end
30
33
 
34
+ begin
35
+ require 'chronic'
36
+ rescue LoadError
37
+ 42
38
+ end
39
+
31
40
  require 'fattr'
32
41
  require 'arrayfields'
33
42
  #
@@ -184,14 +184,6 @@ module Main
184
184
 
185
185
  arity = min
186
186
 
187
- =begin
188
- puts
189
- p :values => values
190
- p :arity => arity
191
- p :argument_required => argument_required?
192
- p :argument_none => argument_none?
193
- puts
194
- =end
195
187
  if values.size < arity
196
188
  if argument_optional?
197
189
  raise ex, "#{ typename }) #{ values.size }/#{ sign }#{ arity }" if(values.size < arity and values.size > 0)
@@ -204,8 +196,14 @@ puts
204
196
  def apply_casting
205
197
  if cast?
206
198
  op = cast.respond_to?('call') ? cast : Cast[cast]
207
- values.map! do |val|
208
- Parameter.wrap_errors{ op.call val }
199
+ case op.arity
200
+ when -1
201
+ replacement = Parameter.wrap_errors{ op.call(*values) }
202
+ values.replace(replacement)
203
+ else
204
+ values.map! do |val|
205
+ Parameter.wrap_errors{ op.call val }
206
+ end
209
207
  end
210
208
  end
211
209
  end
@@ -12,6 +12,7 @@ module Main
12
12
  fattr('stderr'){ main.stderr }
13
13
  fattr('logger'){ main.logger }
14
14
  fattr('params')
15
+ fattr('finalizers')
15
16
 
16
17
  %w(
17
18
  program name synopsis description author version
@@ -50,6 +51,7 @@ module Main
50
51
 
51
52
  def setup_finalizers
52
53
  @finalizers ||= []
54
+ finalizers = @finalizers
53
55
  ObjectSpace.define_finalizer(self) do
54
56
  while((f = finalizers.pop)); f.call; end
55
57
  end
@@ -237,7 +239,7 @@ module Main
237
239
 
238
240
  def fcall(object, method, *argv, &block)
239
241
  method = object.method(method)
240
- arity = m.arity
242
+ arity = method.arity
241
243
  if arity >= 0
242
244
  argv = argv[0, arity]
243
245
  else
@@ -4,11 +4,11 @@
4
4
  Gem::Specification::new do |spec|
5
5
  spec.name = "main"
6
6
  spec.description = 'a class factory and dsl for generating command line programs real quick'
7
- spec.version = "4.2.0"
7
+ spec.version = "4.3.0"
8
8
  spec.platform = Gem::Platform::RUBY
9
9
  spec.summary = "main"
10
10
 
11
- spec.files = ["a.rb", "lib", "lib/main", "lib/main/cast.rb", "lib/main/dsl.rb", "lib/main/factories.rb", "lib/main/getoptlong.rb", "lib/main/logger.rb", "lib/main/mode.rb", "lib/main/parameter.rb", "lib/main/program", "lib/main/program/class_methods.rb", "lib/main/program/instance_methods.rb", "lib/main/program.rb", "lib/main/softspoken.rb", "lib/main/stdext.rb", "lib/main/test.rb", "lib/main/usage.rb", "lib/main/util.rb", "lib/main.rb", "main.gemspec", "Rakefile", "README", "README.erb", "samples", "samples/a.rb", "samples/b.rb", "samples/c.rb", "samples/d.rb", "samples/e.rb", "samples/f.rb", "samples/g.rb", "samples/h.rb", "samples/j.rb", "test", "test/main.rb", "TODO"]
11
+ spec.files = ["a.rb", "lib", "lib/main", "lib/main/cast.rb", "lib/main/dsl.rb", "lib/main/factories.rb", "lib/main/getoptlong.rb", "lib/main/logger.rb", "lib/main/mode.rb", "lib/main/parameter.rb", "lib/main/program", "lib/main/program/class_methods.rb", "lib/main/program/instance_methods.rb", "lib/main/program.rb", "lib/main/softspoken.rb", "lib/main/stdext.rb", "lib/main/test.rb", "lib/main/usage.rb", "lib/main/util.rb", "lib/main.rb", "LICENSE", "main.gemspec", "Rakefile", "README", "README.erb", "samples", "samples/a.rb", "samples/b.rb", "samples/c.rb", "samples/d.rb", "samples/e.rb", "samples/f.rb", "samples/g.rb", "samples/h.rb", "samples/j.rb", "test", "test/main.rb", "TODO"]
12
12
  spec.executables = []
13
13
 
14
14
 
@@ -230,7 +230,7 @@ class T < Test::Unit::TestCase
230
230
  def test_0150
231
231
  param = nil
232
232
  assert_nothing_raised{
233
- main(%w[--foo=42 --bar=42.0 --foobar=true --barfoo=false --uri=http://foo --x=s]){
233
+ main(%w[--foo=42 --bar=42.0 --foobar=true --barfoo=false --uri=http://foo --x=s --y=a,b,c]){
234
234
  option('foo'){
235
235
  required
236
236
  argument_required
@@ -256,15 +256,21 @@ class T < Test::Unit::TestCase
256
256
  argument_required
257
257
  cast{|x| x.to_s.upcase}
258
258
  }
259
+ option('y'){
260
+ argument_required
261
+ process{|*values| values.join.split(',').map{|value| value.upcase}}
262
+ }
259
263
  define_method('run'){ param = params }
260
264
  }
261
265
  }
262
266
  assert param['foo'].value == 42
263
267
  assert param['bar'].value == 42.0
264
- assert param['foobar'].value == true
265
- assert param['barfoo'].value == 'false'
266
- assert param['uri'].value == URI.parse('http://foo')
267
- assert param['x'].value == 'S'
268
+ assert param['foobar'].value == true
269
+ assert param['barfoo'].value == 'false'
270
+ assert param['uri'].value == URI.parse('http://foo')
271
+ assert param['x'].value == 'S'
272
+ assert param['y'].value == 'A'
273
+ assert param['y'].values == %w( A B C )
268
274
  end
269
275
  def test_0160
270
276
  p = nil
@@ -873,6 +879,18 @@ class T < Test::Unit::TestCase
873
879
  }
874
880
  assert( p.nil?, "p should not be set, help should have run" )
875
881
  end
882
+
883
+ def test_0600
884
+ src = 'finalizers should run'
885
+ dst = nil
886
+ argv = []
887
+ assert_nothing_raised{
888
+ main(argv){
889
+ define_method('run'){ finalizers.push(lambda{ dst = src }) }
890
+ }
891
+ }
892
+ assert( src==dst, "appears finalizer did not run!?" )
893
+ end
876
894
  end
877
895
 
878
896
 
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: main
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.0
4
+ hash: 51
5
+ prerelease: false
6
+ segments:
7
+ - 4
8
+ - 3
9
+ - 0
10
+ version: 4.3.0
5
11
  platform: ruby
6
12
  authors:
7
13
  - Ara T. Howard
@@ -9,29 +15,41 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2009-11-02 00:00:00 -07:00
18
+ date: 2010-11-07 01:00:00 -06:00
13
19
  default_executable:
14
20
  dependencies:
15
21
  - !ruby/object:Gem::Dependency
16
22
  name: fattr
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
20
26
  requirements:
21
27
  - - ">="
22
28
  - !ruby/object:Gem::Version
29
+ hash: 11
30
+ segments:
31
+ - 2
32
+ - 1
33
+ - 0
23
34
  version: 2.1.0
24
- version:
35
+ type: :runtime
36
+ version_requirements: *id001
25
37
  - !ruby/object:Gem::Dependency
26
38
  name: arrayfields
27
- type: :runtime
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
30
42
  requirements:
31
43
  - - ">="
32
44
  - !ruby/object:Gem::Version
45
+ hash: 43
46
+ segments:
47
+ - 4
48
+ - 7
49
+ - 4
33
50
  version: 4.7.4
34
- version:
51
+ type: :runtime
52
+ version_requirements: *id002
35
53
  description: a class factory and dsl for generating command line programs real quick
36
54
  email: ara.t.howard@gmail.com
37
55
  executables: []
@@ -58,6 +76,7 @@ files:
58
76
  - lib/main/usage.rb
59
77
  - lib/main/util.rb
60
78
  - lib/main.rb
79
+ - LICENSE
61
80
  - main.gemspec
62
81
  - Rakefile
63
82
  - README
@@ -83,21 +102,27 @@ rdoc_options: []
83
102
  require_paths:
84
103
  - lib
85
104
  required_ruby_version: !ruby/object:Gem::Requirement
105
+ none: false
86
106
  requirements:
87
107
  - - ">="
88
108
  - !ruby/object:Gem::Version
109
+ hash: 3
110
+ segments:
111
+ - 0
89
112
  version: "0"
90
- version:
91
113
  required_rubygems_version: !ruby/object:Gem::Requirement
114
+ none: false
92
115
  requirements:
93
116
  - - ">="
94
117
  - !ruby/object:Gem::Version
118
+ hash: 3
119
+ segments:
120
+ - 0
95
121
  version: "0"
96
- version:
97
122
  requirements: []
98
123
 
99
124
  rubyforge_project: codeforpeople
100
- rubygems_version: 1.3.5
125
+ rubygems_version: 1.3.7
101
126
  signing_key:
102
127
  specification_version: 3
103
128
  summary: main