rubikon 0.5.3 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,7 +3,7 @@
3
3
  #
4
4
  # Copyright (c) 2009-2010, Sebastian Staudt
5
5
 
6
- require 'test_helper'
6
+ require 'helper'
7
7
 
8
8
  class TestConfig < Test::Unit::TestCase
9
9
 
@@ -3,17 +3,18 @@
3
3
  #
4
4
  # Copyright (c) 2010, Sebastian Staudt
5
5
 
6
- require 'test_helper'
6
+ require 'helper'
7
7
  require 'test_parameter'
8
8
 
9
9
  class HasArg
10
10
  include HasArguments
11
11
 
12
- attr_reader :arg_names
13
- public :<<, :active!, :arg_count, :args_full?, :check_args, :more_args?
12
+ attr_reader :arg_names, :arg_values
13
+ public :<<, :active!, :arg_count, :args_full?, :check_args, :more_args?,
14
+ :reset
14
15
 
15
- def initialize(arg_count)
16
- super(DummyApp.instance, 'dummy', arg_count)
16
+ def initialize(*options)
17
+ super DummyApp.instance, 'dummy', *options
17
18
  end
18
19
  end
19
20
 
@@ -22,31 +23,127 @@ class TestHasArguments < Test::Unit::TestCase
22
23
  context 'A parameter with arguments' do
23
24
 
24
25
  should 'allow a Numeric as argument count' do
25
- has_arg = HasArg.new(1)
26
+ has_arg = HasArg.new 1
26
27
  assert_equal 1..1, has_arg.arg_count
27
- assert_nil has_arg.arg_names
28
+ assert_equal [], has_arg.arg_names
29
+ assert_equal ({}), has_arg.arg_values
28
30
  end
29
31
 
30
32
  should 'allow a Range as argument count' do
31
- has_arg = HasArg.new(1..3)
33
+ has_arg = HasArg.new 1..3
32
34
  assert_equal 1..3, has_arg.arg_count
33
- assert_nil has_arg.arg_names
34
- end
35
-
36
- should 'allow an Array as argument count' do
37
- has_arg = HasArg.new([2, 5, 6])
38
- assert_equal 2..6, has_arg.arg_count
39
- assert_nil has_arg.arg_names
35
+ assert_equal [], has_arg.arg_names
36
+ assert_equal ({}), has_arg.arg_values
40
37
  end
41
38
 
42
39
  should 'allow a Symbol Array as argument names' do
43
- has_arg = HasArg.new([:arg1, :arg2, :arg3])
40
+ has_arg = HasArg.new :arg1, :arg2, :arg3
44
41
  assert_equal 3..3, has_arg.arg_count
45
42
  assert_equal [:arg1, :arg2, :arg3], has_arg.arg_names
43
+ assert_equal ({}), has_arg.arg_values
44
+ end
45
+
46
+ should 'allow a argument validation for normal arguments' do
47
+ has_arg = HasArg.new(:arg1, :arg2 => ['string', /regexp/, :numeric])
48
+ assert_equal 2..2, has_arg.arg_count
49
+ assert_equal [:arg1, :arg2], has_arg.arg_names
50
+ assert_equal 1, has_arg.arg_values.size
51
+ assert_equal /^(?-mix:string|(?-mix:regexp)|(?-mix:-?[0-9]+))$/, has_arg.arg_values[:arg2]
52
+
53
+ assert_nothing_raised do
54
+ has_arg << 'test'
55
+ has_arg << 'string'
56
+ has_arg.check_args
57
+ end
58
+
59
+ has_arg.reset
60
+
61
+ assert_nothing_raised do
62
+ has_arg << 'test'
63
+ has_arg << 'regexp'
64
+ has_arg.check_args
65
+ end
66
+
67
+ has_arg.reset
68
+
69
+ assert_nothing_raised do
70
+ has_arg << 'test'
71
+ has_arg << '123'
72
+ has_arg.check_args
73
+ end
74
+ end
75
+
76
+ should 'allow a argument validation for optional arguments' do
77
+ has_arg = HasArg.new(:arg1, :arg2 => [:optional, 'string', /regexp/, :numeric])
78
+ assert_equal 1..2, has_arg.arg_count
79
+ assert_equal [:arg1, :arg2], has_arg.arg_names
80
+ assert_equal 1, has_arg.arg_values.size
81
+ assert_equal /^(?-mix:string|(?-mix:regexp)|(?-mix:-?[0-9]+))$/, has_arg.arg_values[:arg2]
82
+
83
+ assert_nothing_raised do
84
+ has_arg << 'test'
85
+ has_arg.check_args
86
+ end
87
+
88
+ has_arg.reset
89
+
90
+ assert_nothing_raised do
91
+ has_arg << 'test'
92
+ has_arg << 'string'
93
+ has_arg.check_args
94
+ end
95
+
96
+ has_arg.reset
97
+
98
+ assert_nothing_raised do
99
+ has_arg << 'test'
100
+ has_arg << 'regexp'
101
+ has_arg.check_args
102
+ end
103
+
104
+ has_arg.reset
105
+
106
+ assert_nothing_raised do
107
+ has_arg << 'test'
108
+ has_arg << '123'
109
+ has_arg.check_args
110
+ end
111
+ end
112
+
113
+ should 'allow a argument validation for remainder arguments' do
114
+ has_arg = HasArg.new(:arg1, :arg2 => [:remainder, 'string', /regexp/, :numeric])
115
+ assert_equal 2..-1, has_arg.arg_count
116
+ assert_equal [:arg1, :arg2], has_arg.arg_names
117
+ assert_equal 1, has_arg.arg_values.size
118
+ assert_equal /^(?-mix:string|(?-mix:regexp)|(?-mix:-?[0-9]+))$/, has_arg.arg_values[:arg2]
119
+
120
+ assert_raise MissingArgumentError do
121
+ has_arg << 'test'
122
+ has_arg.check_args
123
+ end
124
+
125
+ has_arg.reset
126
+
127
+ assert_raise UnexpectedArgumentError do
128
+ has_arg << 'test'
129
+ has_arg << 'test'
130
+ has_arg.check_args
131
+ end
132
+
133
+ has_arg.reset
134
+
135
+ assert_nothing_raised do
136
+ has_arg << 'test'
137
+ has_arg << 'string'
138
+ has_arg << 'regexp'
139
+ has_arg << '123'
140
+ has_arg.check_args
141
+ end
46
142
  end
47
143
 
48
144
  should 'only have required arguments if argument count is > 0' do
49
- has_arg = HasArg.new(2)
145
+ has_arg = HasArg.new 2
146
+ assert_equal 2..2, has_arg.arg_count
50
147
  assert !has_arg.args_full?
51
148
  assert has_arg.more_args?
52
149
  has_arg << 'argument'
@@ -65,7 +162,8 @@ class TestHasArguments < Test::Unit::TestCase
65
162
  end
66
163
 
67
164
  should 'have required and optional arguments if argument count is < 0' do
68
- has_arg = HasArg.new(-1)
165
+ has_arg = HasArg.new -1
166
+ assert_equal 1..-1, has_arg.arg_count
69
167
  assert !has_arg.args_full?
70
168
  assert has_arg.more_args?
71
169
  assert_raise MissingArgumentError do
@@ -78,7 +176,8 @@ class TestHasArguments < Test::Unit::TestCase
78
176
  end
79
177
 
80
178
  should 'only have optional arguments if argument count is 0' do
81
- has_arg = HasArg.new(0)
179
+ has_arg = HasArg.new 0
180
+ assert_equal 0..-1, has_arg.arg_count
82
181
  assert has_arg.args_full?
83
182
  assert has_arg.more_args?
84
183
  has_arg << 'argument'
@@ -86,7 +185,8 @@ class TestHasArguments < Test::Unit::TestCase
86
185
  end
87
186
 
88
187
  should 'provide named arguments' do
89
- has_arg = HasArg.new([:named])
188
+ has_arg = HasArg.new :named
189
+ assert_equal 1..1, has_arg.arg_count
90
190
  has_arg << 'argument'
91
191
  assert_equal 'argument', has_arg[:named]
92
192
  assert_equal 'argument', has_arg.named
@@ -95,6 +195,47 @@ class TestHasArguments < Test::Unit::TestCase
95
195
  end
96
196
  end
97
197
 
198
+ should 'provide optional named arguments' do
199
+ has_arg = HasArg.new :required, :optional => :optional
200
+ assert_equal 1..2, has_arg.arg_count
201
+ has_arg << 'argument'
202
+ assert has_arg.args_full?
203
+ assert has_arg.more_args?
204
+ has_arg << 'argument'
205
+ assert !has_arg.more_args?
206
+ assert_equal 'argument', has_arg.required
207
+ assert_equal 'argument', has_arg.optional
208
+ end
209
+
210
+ should 'provide named arguments taking all remaining arguments' do
211
+ has_arg = HasArg.new :required, :remainder => :remainder
212
+ assert_equal 2..-1, has_arg.arg_count
213
+ has_arg << 'argument'
214
+ assert !has_arg.args_full?
215
+ assert has_arg.more_args?
216
+ has_arg << 'argument'
217
+ assert has_arg.args_full?
218
+ assert has_arg.more_args?
219
+ has_arg << 'argument'
220
+ assert has_arg.more_args?
221
+ assert_equal 'argument', has_arg.required
222
+ assert_equal %w{argument argument}, has_arg.remainder
223
+ end
224
+
225
+ should 'provide named arguments optionally taking all remaining arguments' do
226
+ has_arg = HasArg.new :required, :remainder => [:optional, :remainder]
227
+ assert_equal 1..-1, has_arg.arg_count
228
+ has_arg << 'argument'
229
+ assert has_arg.args_full?
230
+ assert has_arg.more_args?
231
+ has_arg << 'argument'
232
+ assert has_arg.more_args?
233
+ has_arg << 'argument'
234
+ assert has_arg.more_args?
235
+ assert_equal 'argument', has_arg.required
236
+ assert_equal %w{argument argument}, has_arg.remainder
237
+ end
238
+
98
239
  should 'call its code block if it is activated' do
99
240
  block_run = false
100
241
  has_arg = HasArg.new nil do
@@ -3,7 +3,7 @@
3
3
  #
4
4
  # Copyright (c) 2010, Sebastian Staudt
5
5
 
6
- require 'test_helper'
6
+ require 'helper'
7
7
 
8
8
  class TestIniProvider < Test::Unit::TestCase
9
9
 
@@ -3,7 +3,7 @@
3
3
  #
4
4
  # Copyright (c) 2010, Sebastian Staudt
5
5
 
6
- require 'test_helper'
6
+ require 'helper'
7
7
  require 'testapps'
8
8
 
9
9
  module TestParameter
@@ -3,7 +3,7 @@
3
3
  #
4
4
  # Copyright (c) 2009-2010, Sebastian Staudt
5
5
 
6
- require 'test_helper'
6
+ require 'helper'
7
7
 
8
8
  class TestProgressBar < Test::Unit::TestCase
9
9
 
@@ -3,7 +3,7 @@
3
3
  #
4
4
  # Copyright (c) 2009-2010, Sebastian Staudt
5
5
 
6
- require 'test_helper'
6
+ require 'helper'
7
7
 
8
8
  class TestThrobber < Test::Unit::TestCase
9
9
 
@@ -1,7 +1,7 @@
1
1
  # This code is free software; you can redistribute it and/or modify it under
2
2
  # the terms of the new BSD License.
3
3
  #
4
- # Copyright (c) 2009-2010, Sebastian Staudt
4
+ # Copyright (c) 2009-2011, Sebastian Staudt
5
5
 
6
6
  class DummyApp < Application::Base
7
7
 
@@ -13,10 +13,13 @@ end
13
13
 
14
14
  class TestApp < Application::Base
15
15
 
16
+ set :autohelp, false
16
17
  set :autorun, false
17
18
  set :name, 'Rubikon test application'
18
19
  set :raise_errors, true
19
20
 
21
+ attr_reader :commands, :global_parameters
22
+
20
23
  global_flag :gf1 => :gflag
21
24
  global_flag :gflag do
22
25
  @global = 'flag'
@@ -29,22 +32,22 @@ class TestApp < Application::Base
29
32
  end
30
33
  global_option :go2 => :gopt
31
34
 
32
- default do
35
+ default '<hidden>' do
33
36
  'default command'
34
37
  end
35
38
 
36
- option :arg, [:opt_arg] do
39
+ option :arg, :opt_arg do
37
40
  @result = []
38
41
  @result << opt_arg
39
42
  end
40
- command :arguments, [:cmd_arg] do
43
+ command :arguments, :cmd_arg do
41
44
  @result << arg.opt_arg
42
45
  @result << cmd_arg
43
46
  @result
44
47
  end
45
48
 
46
49
  command :input do
47
- input 'input'
50
+ [input('input'), input('validated', 'x')]
48
51
  end
49
52
 
50
53
  command :alias_before => :object_id
@@ -94,6 +97,8 @@ class TestAppWithoutDefault < Application::Base
94
97
  set :help_as_default, false
95
98
  set :raise_errors, true
96
99
 
100
+ attr_reader :commands
101
+
97
102
  end
98
103
 
99
104
  class TestAppWithHooks < Application::Base
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubikon
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
5
- prerelease: false
4
+ hash: 7
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
- - 5
9
- - 3
10
- version: 0.5.3
8
+ - 6
9
+ - 0
10
+ version: 0.6.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sebastian Staudt
@@ -15,21 +15,23 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-12-09 00:00:00 +01:00
18
+ date: 2011-01-23 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- name: jeweler
22
+ name: ore-tasks
23
23
  prerelease: false
24
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
- - - ">="
27
+ - - ~>
28
28
  - !ruby/object:Gem::Version
29
- hash: 3
29
+ hash: 19
30
30
  segments:
31
31
  - 0
32
- version: "0"
32
+ - 3
33
+ - 0
34
+ version: 0.3.0
33
35
  type: :development
34
36
  version_requirements: *id001
35
37
  - !ruby/object:Gem::Dependency
@@ -38,12 +40,14 @@ dependencies:
38
40
  requirement: &id002 !ruby/object:Gem::Requirement
39
41
  none: false
40
42
  requirements:
41
- - - ">="
43
+ - - ~>
42
44
  - !ruby/object:Gem::Version
43
- hash: 3
45
+ hash: 37
44
46
  segments:
45
- - 0
46
- version: "0"
47
+ - 2
48
+ - 11
49
+ - 3
50
+ version: 2.11.3
47
51
  type: :development
48
52
  version_requirements: *id002
49
53
  - !ruby/object:Gem::Dependency
@@ -52,12 +56,14 @@ dependencies:
52
56
  requirement: &id003 !ruby/object:Gem::Requirement
53
57
  none: false
54
58
  requirements:
55
- - - ">="
59
+ - - ~>
56
60
  - !ruby/object:Gem::Version
57
- hash: 3
61
+ hash: 15
58
62
  segments:
59
63
  - 0
60
- version: "0"
64
+ - 6
65
+ - 4
66
+ version: 0.6.4
61
67
  type: :development
62
68
  version_requirements: *id003
63
69
  description: A simple to use, yet powerful Ruby framework for building console-based applications.
@@ -67,53 +73,63 @@ executables: []
67
73
  extensions: []
68
74
 
69
75
  extra_rdoc_files:
70
- - LICENSE
71
76
  - README.md
72
77
  files:
73
- - .yardopts
74
- - LICENSE
75
- - README.md
76
- - Rakefile
77
- - lib/core_ext/object.rb
78
- - lib/core_ext/string.rb
79
- - lib/rubikon.rb
80
- - lib/rubikon/application/base.rb
81
- - lib/rubikon/application/class_methods.rb
82
- - lib/rubikon/application/dsl_methods.rb
83
- - lib/rubikon/application/instance_methods.rb
84
- - lib/rubikon/application/sandbox.rb
85
- - lib/rubikon/colored_io.rb
86
- - lib/rubikon/command.rb
87
- - lib/rubikon/config/auto_provider.rb
88
- - lib/rubikon/config/factory.rb
89
- - lib/rubikon/config/ini_provider.rb
78
+ - test/test_argument_vector.rb
90
79
  - lib/rubikon/config/yaml_provider.rb
91
- - lib/rubikon/exceptions.rb
92
- - lib/rubikon/flag.rb
93
- - lib/rubikon/has_arguments.rb
94
- - lib/rubikon/option.rb
95
- - lib/rubikon/parameter.rb
96
- - lib/rubikon/progress_bar.rb
97
- - lib/rubikon/throbber.rb
80
+ - gemspec.yml
98
81
  - samples/config/config_sample.rb
99
- - samples/helloworld/hello_world.rb
100
- - test/commands/external_command.rb
101
- - test/test_application.rb
102
- - test/test_command.rb
103
- - test/test_config.rb
104
- - test/test_flag.rb
105
- - test/test_has_arguments.rb
106
- - test/test_helper.rb
82
+ - lib/rubikon/config/factory.rb
83
+ - lib/rubikon/command.rb
84
+ - lib/rubikon/application/base.rb
85
+ - .yardopts
107
86
  - test/test_ini_provider.rb
108
87
  - test/test_option.rb
109
- - test/test_parameter.rb
88
+ - test/test_config.rb
89
+ - LICENSE
90
+ - test/config/test.ini
91
+ - samples/helloworld/hello_world.rb
92
+ - lib/rubikon/colored_io.rb
93
+ - lib/rubikon/application/class_methods.rb
94
+ - test/test_command.rb
95
+ - test/config/2/config.yml
96
+ - test/config/0/config.yml
97
+ - samples/config/local/config.yml
98
+ - lib/rubikon/parameter.rb
99
+ - lib/rubikon/option.rb
100
+ - lib/rubikon/flag.rb
101
+ - lib/core_ext/enumerable.rb
102
+ - Rakefile
103
+ - README.md
110
104
  - test/test_progress_bar.rb
105
+ - test/test_flag.rb
106
+ - test/config/1/config.yml
107
+ - lib/rubikon/progress_bar.rb
108
+ - lib/rubikon/has_arguments.rb
109
+ - lib/rubikon/application/sandbox.rb
111
110
  - test/test_throbber.rb
111
+ - test/test_parameter.rb
112
+ - test/test_has_arguments.rb
113
+ - test/commands/external_command.rb
114
+ - lib/rubikon/argument_vector.rb
115
+ - lib/rubikon/errors.rb
116
+ - lib/rubikon/application/instance_methods.rb
112
117
  - test/testapps.rb
113
- has_rdoc: false
118
+ - lib/rubikon/version.rb
119
+ - lib/rubikon/throbber.rb
120
+ - lib/core_ext/string.rb
121
+ - lib/core_ext/object.rb
122
+ - test/test_application.rb
123
+ - test/helper.rb
124
+ - samples/config/global/config.yml
125
+ - lib/rubikon/config/ini_provider.rb
126
+ - lib/rubikon/config/auto_provider.rb
127
+ - lib/rubikon/application/dsl_methods.rb
128
+ - lib/rubikon.rb
129
+ has_rdoc: true
114
130
  homepage: http://koraktor.github.com/rubikon
115
- licenses: []
116
-
131
+ licenses:
132
+ - BSD
117
133
  post_install_message:
118
134
  rdoc_options: []
119
135
 
@@ -140,21 +156,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
140
156
  requirements: []
141
157
 
142
158
  rubyforge_project: rubikon
143
- rubygems_version: 1.3.7
159
+ rubygems_version: 1.4.2
144
160
  signing_key:
145
161
  specification_version: 3
146
162
  summary: Rubikon - A Ruby console app framework
147
- test_files:
148
- - test/commands/external_command.rb
149
- - test/test_application.rb
150
- - test/test_command.rb
151
- - test/test_config.rb
152
- - test/test_flag.rb
153
- - test/test_has_arguments.rb
154
- - test/test_helper.rb
155
- - test/test_ini_provider.rb
156
- - test/test_option.rb
157
- - test/test_parameter.rb
158
- - test/test_progress_bar.rb
159
- - test/test_throbber.rb
160
- - test/testapps.rb
163
+ test_files: []
164
+