voke 0.0.1
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.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/examples/arguments.rb +18 -0
- data/examples/hello_world.rb +13 -0
- data/lib/voke.rb +158 -0
- data/lib/voke/version.rb +3 -0
- data/test/voke_test.rb +290 -0
- data/voke.gemspec +21 -0
- metadata +73 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Luke Curley
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Voke
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'voke'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install voke
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'voke'
|
3
|
+
|
4
|
+
class Arguments
|
5
|
+
include Voke
|
6
|
+
|
7
|
+
default :greet, "world"
|
8
|
+
default :excited do |options|
|
9
|
+
options[:greet] == "world"
|
10
|
+
end
|
11
|
+
|
12
|
+
def list(*args, options)
|
13
|
+
puts "arguments: #{ args.inspect }"
|
14
|
+
puts "options: #{ options.inspect }"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
Arguments.new.voke("list", *ARGV)
|
data/lib/voke.rb
ADDED
@@ -0,0 +1,158 @@
|
|
1
|
+
require "voke/version"
|
2
|
+
|
3
|
+
module Voke
|
4
|
+
def self.included(klass)
|
5
|
+
klass.extend(ClassMethods)
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.extended(klass)
|
9
|
+
klass.extend(ClassMethods)
|
10
|
+
end
|
11
|
+
|
12
|
+
def help(command, *args)
|
13
|
+
command = command.to_sym rescue nil
|
14
|
+
|
15
|
+
if command and respond_to?(command)
|
16
|
+
methods = [ command ]
|
17
|
+
else
|
18
|
+
methods = self.class.public_instance_methods(false)
|
19
|
+
end
|
20
|
+
|
21
|
+
methods.each do |method_name|
|
22
|
+
method = self.method(method_name)
|
23
|
+
parameters = method.parameters
|
24
|
+
|
25
|
+
# remove the options parameter
|
26
|
+
parameters.pop
|
27
|
+
|
28
|
+
parts = parameters.collect do |type, name|
|
29
|
+
case type
|
30
|
+
when :req
|
31
|
+
name
|
32
|
+
when :opt
|
33
|
+
"[#{ name }]"
|
34
|
+
when :part
|
35
|
+
"#{ name }*"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def voke(*args)
|
42
|
+
args = ARGV if args.empty?
|
43
|
+
|
44
|
+
command, arguments, options = voke_parse(*args)
|
45
|
+
voke_call(command, arguments, options)
|
46
|
+
end
|
47
|
+
|
48
|
+
def voke_call(command, arguments, options)
|
49
|
+
begin
|
50
|
+
method = method(command.to_sym)
|
51
|
+
rescue
|
52
|
+
return help(command, *arguments, options)
|
53
|
+
end
|
54
|
+
|
55
|
+
method.call(*arguments, options)
|
56
|
+
end
|
57
|
+
|
58
|
+
def voke_parse(*args)
|
59
|
+
command = args.shift
|
60
|
+
arguments = Array.new
|
61
|
+
options = Hash.new
|
62
|
+
|
63
|
+
args.each do |arg|
|
64
|
+
if arg =~ /^--(\w+)(?:=(.*))?$/
|
65
|
+
key = $1.to_sym
|
66
|
+
|
67
|
+
value = true
|
68
|
+
value = voke_parse_value($2) if $2
|
69
|
+
|
70
|
+
options[key] = value
|
71
|
+
else
|
72
|
+
key = nil
|
73
|
+
value = voke_parse_value(arg)
|
74
|
+
|
75
|
+
arguments << value
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
[ command, arguments, options ]
|
80
|
+
end
|
81
|
+
|
82
|
+
def voke_parse_value(value)
|
83
|
+
case value
|
84
|
+
when "", "nil"
|
85
|
+
nil
|
86
|
+
when "true"
|
87
|
+
true
|
88
|
+
when "false"
|
89
|
+
false
|
90
|
+
when /^-?\d+$/
|
91
|
+
value.to_i
|
92
|
+
when /^-?\d*\.\d*$/
|
93
|
+
value.to_f
|
94
|
+
when /^['"](.+)['"]$/
|
95
|
+
$1
|
96
|
+
when /^(.*),(.*)$/
|
97
|
+
value = value.split(',')
|
98
|
+
value.collect { |v| voke_parse_value(v) }
|
99
|
+
else
|
100
|
+
value
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
module ClassMethods
|
105
|
+
def voke_config(name)
|
106
|
+
@voke_config ||= Hash.new
|
107
|
+
@voke_config[name] ||= { :defaults => Hash.new }
|
108
|
+
end
|
109
|
+
|
110
|
+
def description(method = :voke_next, string)
|
111
|
+
config = voke_config(method)
|
112
|
+
config[:description] = string
|
113
|
+
end
|
114
|
+
|
115
|
+
def default(*args, &block)
|
116
|
+
value = block || args.pop
|
117
|
+
argument = args.pop
|
118
|
+
method = args.pop || :voke_next
|
119
|
+
|
120
|
+
config = voke_config(method)
|
121
|
+
config[:defaults][argument] = value
|
122
|
+
end
|
123
|
+
|
124
|
+
def method_added(method)
|
125
|
+
config = voke_config(method)
|
126
|
+
|
127
|
+
return if config[:added]
|
128
|
+
return if not public_method_defined?(method)
|
129
|
+
|
130
|
+
config[:added] = true
|
131
|
+
|
132
|
+
if next_config = @voke_config.delete(:voke_next)
|
133
|
+
config[:description] ||= next_config[:description]
|
134
|
+
config[:defaults] = next_config[:defaults].merge(config[:defaults])
|
135
|
+
end
|
136
|
+
|
137
|
+
orig_method = instance_method(method)
|
138
|
+
|
139
|
+
define_method(method) do |*args, &block|
|
140
|
+
if args.last.is_a?(Hash)
|
141
|
+
options = args.pop
|
142
|
+
|
143
|
+
config = self.class.voke_config(method)
|
144
|
+
config[:defaults].each do |key, value|
|
145
|
+
unless options[key]
|
146
|
+
value = value.call(options) if value.is_a?(Proc) or value.is_a?(Method)
|
147
|
+
options[key] = value
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
args.push(options)
|
152
|
+
end
|
153
|
+
|
154
|
+
orig_method.bind(self).call(*args, &block)
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
data/lib/voke/version.rb
ADDED
data/test/voke_test.rb
ADDED
@@ -0,0 +1,290 @@
|
|
1
|
+
require "minitest/autorun"
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "voke"
|
5
|
+
|
6
|
+
class TestVoke
|
7
|
+
include Voke
|
8
|
+
end
|
9
|
+
|
10
|
+
describe Voke do
|
11
|
+
describe ".voke_parse" do
|
12
|
+
def voke_parse(*args)
|
13
|
+
TestVoke.new.voke_parse(*args)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "parses empty values on empty" do
|
17
|
+
result = voke_parse()
|
18
|
+
result.must_equal [ nil, [], {} ]
|
19
|
+
end
|
20
|
+
|
21
|
+
it "parses the command" do
|
22
|
+
result = voke_parse("foo")
|
23
|
+
result.must_equal [ "foo", [], {} ]
|
24
|
+
end
|
25
|
+
|
26
|
+
it "parses the command and arguments" do
|
27
|
+
result = voke_parse("foo", "bar", "world")
|
28
|
+
result.must_equal [ "foo", [ "bar", "world" ], {} ]
|
29
|
+
end
|
30
|
+
|
31
|
+
it "parses nils in arguments" do
|
32
|
+
result = voke_parse("foo", "nil")
|
33
|
+
result.must_equal [ "foo", [ nil ], {} ]
|
34
|
+
end
|
35
|
+
|
36
|
+
it "parses booleans in arguments" do
|
37
|
+
result = voke_parse("foo", "true", "false")
|
38
|
+
result.must_equal [ "foo", [ true, false ], {} ]
|
39
|
+
end
|
40
|
+
|
41
|
+
it "parses integers in arguments" do
|
42
|
+
result = voke_parse("foo", "4", "-3")
|
43
|
+
result.must_equal [ "foo", [ 4, -3 ], {} ]
|
44
|
+
end
|
45
|
+
|
46
|
+
it "parses floats in arguments" do
|
47
|
+
result = voke_parse("foo", "1.2", ".67", "-5.76", "-.5")
|
48
|
+
result.must_equal [ "foo", [ 1.2, 0.67, -5.76, -0.5 ], {} ]
|
49
|
+
end
|
50
|
+
|
51
|
+
it "parses quoted strings in arguments" do
|
52
|
+
result = voke_parse("foo", "'4'", "\"hamburger,fries\"")
|
53
|
+
result.must_equal [ "foo", [ "4", "hamburger,fries" ], {} ]
|
54
|
+
end
|
55
|
+
|
56
|
+
it "parses arrays in arguments" do
|
57
|
+
result = voke_parse("foo", "hamburger,fries", ",")
|
58
|
+
result.must_equal [ "foo", [ [ "hamburger", "fries" ], [] ], {} ]
|
59
|
+
end
|
60
|
+
|
61
|
+
it "parses values inside arrays in arguments" do
|
62
|
+
result = voke_parse("foo", "-4,false,\"nil\",0.76")
|
63
|
+
result.must_equal [ "foo", [ [ -4, false, "nil", 0.76 ] ], {} ]
|
64
|
+
end
|
65
|
+
|
66
|
+
it "parses the command and options" do
|
67
|
+
result = voke_parse("foo", "--hello=world")
|
68
|
+
result.must_equal [ "foo", [], { :hello => "world" } ]
|
69
|
+
end
|
70
|
+
|
71
|
+
it "parses the command, arguments, and options" do
|
72
|
+
result = voke_parse("foo", "--hello=world", "bar", "--apple=fruit")
|
73
|
+
result.must_equal [ "foo", [ "bar" ], { :hello => "world", :apple => "fruit" } ]
|
74
|
+
end
|
75
|
+
|
76
|
+
it "defaults to true in options" do
|
77
|
+
result = voke_parse("foo", "--hello")
|
78
|
+
result.must_equal [ "foo", [], { :hello => true } ]
|
79
|
+
end
|
80
|
+
|
81
|
+
it "parses nils in options" do
|
82
|
+
result = voke_parse("foo", "--hello=", "--world=nil")
|
83
|
+
result.must_equal [ "foo", [], { :hello => nil, :world => nil } ]
|
84
|
+
end
|
85
|
+
|
86
|
+
it "parses booleans in options" do
|
87
|
+
result = voke_parse("foo", "--hello=true", "--goodbye=false")
|
88
|
+
result.must_equal [ "foo", [], { :hello => true, :goodbye => false } ]
|
89
|
+
end
|
90
|
+
|
91
|
+
it "parses integers in options" do
|
92
|
+
result = voke_parse("foo", "--foo=4", "--bar=-3")
|
93
|
+
result.must_equal [ "foo", [], { :foo => 4, :bar => -3 } ]
|
94
|
+
end
|
95
|
+
|
96
|
+
it "parses floats in options" do
|
97
|
+
result = voke_parse("foo", "--foo=1.2", "--bar=.67", "--hello=-5.76", "--world=-.5")
|
98
|
+
result.must_equal [ "foo", [], { :foo => 1.2, :bar => 0.67, :hello => -5.76, :world => -0.5 } ]
|
99
|
+
end
|
100
|
+
|
101
|
+
it "parses quoted strings in options" do
|
102
|
+
result = voke_parse("foo", "--foo='4'", "--bar=\"hamburger,fries\"")
|
103
|
+
result.must_equal [ "foo", [], { :foo => "4", :bar => "hamburger,fries" } ]
|
104
|
+
end
|
105
|
+
|
106
|
+
it "parses arrays in options" do
|
107
|
+
result = voke_parse("foo", "--foo=hamburger,fries")
|
108
|
+
result.must_equal [ "foo", [], { :foo => [ "hamburger", "fries" ] } ]
|
109
|
+
end
|
110
|
+
|
111
|
+
it "parses values inside arrays in arguments" do
|
112
|
+
result = voke_parse("foo", "--foo=-4,false,\"nil\",0.76")
|
113
|
+
result.must_equal [ "foo", [], { :foo => [ -4, false, "nil", 0.76 ] } ]
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
describe ".voke_call" do
|
118
|
+
# some helpers to make results more obvious
|
119
|
+
ARG1 = :arg1
|
120
|
+
ARG2 = :arg2
|
121
|
+
ARG3 = :arg3
|
122
|
+
OPTIONS = { :option1 => 1, :option2 => 2 }
|
123
|
+
|
124
|
+
def voke_call(method, *args)
|
125
|
+
TestVoke.new.voke_call(method, args, OPTIONS)
|
126
|
+
end
|
127
|
+
|
128
|
+
describe "zero option definition" do
|
129
|
+
class TestVoke
|
130
|
+
def m0;[];end
|
131
|
+
end
|
132
|
+
|
133
|
+
it "calls with no arguments" do
|
134
|
+
lambda { voke_call(:m0) }.must_raise ArgumentError
|
135
|
+
end
|
136
|
+
|
137
|
+
it "calls with one argument" do
|
138
|
+
lambda { voke_call(:m0, ARG1) }.must_raise ArgumentError
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
describe "one option definition" do
|
143
|
+
class TestVoke
|
144
|
+
def m1(a);[a];end
|
145
|
+
def m2(a=nil);[a];end
|
146
|
+
def n1(*a);a;end
|
147
|
+
end
|
148
|
+
|
149
|
+
it "calls with no arguments" do
|
150
|
+
voke_call(:m1).must_equal [ OPTIONS ]
|
151
|
+
voke_call(:m2).must_equal [ OPTIONS ]
|
152
|
+
voke_call(:n1).must_equal [ OPTIONS ]
|
153
|
+
end
|
154
|
+
|
155
|
+
it "calls with one argument" do
|
156
|
+
lambda { voke_call(:m1, ARG1) }.must_raise ArgumentError
|
157
|
+
lambda { voke_call(:m2, ARG1) }.must_raise ArgumentError
|
158
|
+
voke_call(:n1, ARG1).must_equal [ ARG1, OPTIONS ]
|
159
|
+
end
|
160
|
+
|
161
|
+
it "calls with two arguments" do
|
162
|
+
lambda { voke_call(:m1, ARG1, ARG2) }.must_raise ArgumentError
|
163
|
+
lambda { voke_call(:m2, ARG1, ARG2) }.must_raise ArgumentError
|
164
|
+
voke_call(:n1, ARG1, ARG2).must_equal [ ARG1, ARG2, OPTIONS ]
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
describe "two option definition" do
|
169
|
+
class TestVoke
|
170
|
+
def m3(a,b);[a,b];end
|
171
|
+
def m4(a,b=nil);[a,b];end
|
172
|
+
def m5(a=nil,b);[a,b];end
|
173
|
+
def m6(a=nil,b=nil);[a,b];end
|
174
|
+
|
175
|
+
def n2(a,*b);[a]+b;end
|
176
|
+
def n3(a=nil,*b);[a]+b;end
|
177
|
+
def n4(*a,b);a+[b];end
|
178
|
+
#def n5(*a,b=nil);a+[b];end # does not exist
|
179
|
+
end
|
180
|
+
|
181
|
+
it "calls with no arguments" do
|
182
|
+
lambda { voke_call(:m3) }.must_raise ArgumentError
|
183
|
+
voke_call(:m4).must_equal [ OPTIONS, nil ]
|
184
|
+
voke_call(:m5).must_equal [ nil, OPTIONS ]
|
185
|
+
voke_call(:m6).must_equal [ OPTIONS, nil ]
|
186
|
+
|
187
|
+
voke_call(:n2).must_equal [ OPTIONS ]
|
188
|
+
voke_call(:n3).must_equal [ OPTIONS ]
|
189
|
+
voke_call(:n4).must_equal [ OPTIONS ]
|
190
|
+
end
|
191
|
+
|
192
|
+
it "calls with one argument" do
|
193
|
+
voke_call(:m3, ARG1).must_equal [ ARG1, OPTIONS ]
|
194
|
+
voke_call(:m4, ARG1).must_equal [ ARG1, OPTIONS ]
|
195
|
+
voke_call(:m5, ARG1).must_equal [ ARG1, OPTIONS ]
|
196
|
+
voke_call(:m6, ARG1).must_equal [ ARG1, OPTIONS ]
|
197
|
+
|
198
|
+
voke_call(:n2, ARG1).must_equal [ ARG1, OPTIONS ]
|
199
|
+
voke_call(:n3, ARG1).must_equal [ ARG1, OPTIONS ]
|
200
|
+
voke_call(:n4, ARG1).must_equal [ ARG1, OPTIONS ]
|
201
|
+
end
|
202
|
+
|
203
|
+
it "calls with two arguments" do
|
204
|
+
lambda { voke_call(:m3, ARG1, ARG2) }.must_raise ArgumentError
|
205
|
+
lambda { voke_call(:m4, ARG1, ARG2) }.must_raise ArgumentError
|
206
|
+
lambda { voke_call(:m5, ARG1, ARG2) }.must_raise ArgumentError
|
207
|
+
lambda { voke_call(:m6, ARG1, ARG2) }.must_raise ArgumentError
|
208
|
+
|
209
|
+
voke_call(:n2, ARG1, ARG2).must_equal [ ARG1, ARG2, OPTIONS ]
|
210
|
+
voke_call(:n3, ARG1, ARG2).must_equal [ ARG1, ARG2, OPTIONS ]
|
211
|
+
voke_call(:n4, ARG1, ARG2).must_equal [ ARG1, ARG2, OPTIONS ]
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
describe "three option definition" do
|
216
|
+
class TestVoke
|
217
|
+
def m7(a,b,c);[a,b,c];end
|
218
|
+
def m8(a,b,c=nil);[a,b,c];end
|
219
|
+
def m9(a,b=nil,c);[a,b,c];end
|
220
|
+
def m10(a,b=nil,c=nil);[a,b,c];end
|
221
|
+
def m11(a=nil,b,c);[a,b,c];end
|
222
|
+
#def m12(a=nil,b,c=nil);[a,b,c];end # does not exist
|
223
|
+
def m12(a=nil,b=nil,c);[a,b,c];end
|
224
|
+
def m13(a=nil,b=nil,c=nil);[a,b,c];end
|
225
|
+
|
226
|
+
def n5(a,b,*c);[a,b]+c;end
|
227
|
+
def n6(a,*b,c);[a]+b+[c];end
|
228
|
+
def n7(*a,b,c);a+[b,c];end
|
229
|
+
end
|
230
|
+
|
231
|
+
it "calls with no arguments" do
|
232
|
+
lambda { voke_call(:m7) }.must_raise ArgumentError
|
233
|
+
lambda { voke_call(:m8) }.must_raise ArgumentError
|
234
|
+
lambda { voke_call(:m9) }.must_raise ArgumentError
|
235
|
+
voke_call(:m10).must_equal [ OPTIONS, nil, nil ]
|
236
|
+
lambda { voke_call(:m11) }.must_raise ArgumentError
|
237
|
+
voke_call(:m12).must_equal [ nil, nil, OPTIONS ]
|
238
|
+
voke_call(:m13).must_equal [ OPTIONS, nil, nil ]
|
239
|
+
|
240
|
+
lambda { voke_call(:n5) }.must_raise ArgumentError
|
241
|
+
lambda { voke_call(:n6) }.must_raise ArgumentError
|
242
|
+
lambda { voke_call(:n7) }.must_raise ArgumentError
|
243
|
+
end
|
244
|
+
|
245
|
+
it "calls with one argument" do
|
246
|
+
lambda { voke_call(:m7, ARG1) }.must_raise ArgumentError
|
247
|
+
voke_call(:m8, ARG1).must_equal [ ARG1, OPTIONS, nil ]
|
248
|
+
voke_call(:m9, ARG1).must_equal [ ARG1, nil, OPTIONS ]
|
249
|
+
voke_call(:m10, ARG1).must_equal [ ARG1, OPTIONS, nil ] # not ideal
|
250
|
+
#voke_call(:m10, ARG1).must_equal [ ARG1, nil, OPTIONS ]
|
251
|
+
voke_call(:m11, ARG1).must_equal [ nil, ARG1, OPTIONS ]
|
252
|
+
voke_call(:m12, ARG1).must_equal [ ARG1, nil, OPTIONS ]
|
253
|
+
voke_call(:m13, ARG1).must_equal [ ARG1, OPTIONS, nil ] # not ideal
|
254
|
+
#voke_call(:m13, ARG1).must_equal [ ARG1, nil, OPTIONS ]
|
255
|
+
|
256
|
+
lambda { voke_call(:n5) }.must_raise ArgumentError
|
257
|
+
lambda { voke_call(:n6) }.must_raise ArgumentError
|
258
|
+
lambda { voke_call(:n7) }.must_raise ArgumentError
|
259
|
+
end
|
260
|
+
|
261
|
+
it "calls with two arguments" do
|
262
|
+
voke_call(:m7, ARG1, ARG2).must_equal [ ARG1, ARG2, OPTIONS ]
|
263
|
+
voke_call(:m8, ARG1, ARG2).must_equal [ ARG1, ARG2, OPTIONS ]
|
264
|
+
voke_call(:m9, ARG1, ARG2).must_equal [ ARG1, ARG2, OPTIONS ]
|
265
|
+
voke_call(:m10, ARG1, ARG2).must_equal [ ARG1, ARG2, OPTIONS ]
|
266
|
+
voke_call(:m11, ARG1, ARG2).must_equal [ ARG1, ARG2, OPTIONS ]
|
267
|
+
voke_call(:m12, ARG1, ARG2).must_equal [ ARG1, ARG2, OPTIONS ]
|
268
|
+
voke_call(:m13, ARG1, ARG2).must_equal [ ARG1, ARG2, OPTIONS ]
|
269
|
+
|
270
|
+
voke_call(:n5, ARG1, ARG2).must_equal [ ARG1, ARG2, OPTIONS ]
|
271
|
+
voke_call(:n6, ARG1, ARG2).must_equal [ ARG1, ARG2, OPTIONS ]
|
272
|
+
voke_call(:n7, ARG1, ARG2).must_equal [ ARG1, ARG2, OPTIONS ]
|
273
|
+
end
|
274
|
+
|
275
|
+
it "calls with three arguments" do
|
276
|
+
lambda { voke_call(:m7, ARG1, ARG2, ARG3) }.must_raise ArgumentError
|
277
|
+
lambda { voke_call(:m8, ARG1, ARG2, ARG3) }.must_raise ArgumentError
|
278
|
+
lambda { voke_call(:m9, ARG1, ARG2, ARG3) }.must_raise ArgumentError
|
279
|
+
lambda { voke_call(:m10, ARG1, ARG2, ARG3) }.must_raise ArgumentError
|
280
|
+
lambda { voke_call(:m11, ARG1, ARG2, ARG3) }.must_raise ArgumentError
|
281
|
+
lambda { voke_call(:m12, ARG1, ARG2, ARG3) }.must_raise ArgumentError
|
282
|
+
lambda { voke_call(:m13, ARG1, ARG2, ARG3) }.must_raise ArgumentError
|
283
|
+
|
284
|
+
voke_call(:n5, ARG1, ARG2, ARG3).must_equal [ ARG1, ARG2, ARG3, OPTIONS ]
|
285
|
+
voke_call(:n6, ARG1, ARG2, ARG3).must_equal [ ARG1, ARG2, ARG3, OPTIONS ]
|
286
|
+
voke_call(:n7, ARG1, ARG2, ARG3).must_equal [ ARG1, ARG2, ARG3, OPTIONS ]
|
287
|
+
end
|
288
|
+
end
|
289
|
+
end
|
290
|
+
end
|
data/voke.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'voke/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "voke"
|
8
|
+
gem.version = Voke::VERSION
|
9
|
+
gem.authors = ["Luke Curley"]
|
10
|
+
gem.email = ["qpingu@gmail.com"]
|
11
|
+
gem.description = %q{Minimal CLI}
|
12
|
+
gem.summary = %q{Minimal CLI}
|
13
|
+
gem.homepage = ""
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_development_dependency "minitest"
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: voke
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Luke Curley
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-06 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: minitest
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: Minimal CLI
|
31
|
+
email:
|
32
|
+
- qpingu@gmail.com
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- Gemfile
|
39
|
+
- LICENSE.txt
|
40
|
+
- README.md
|
41
|
+
- Rakefile
|
42
|
+
- examples/arguments.rb
|
43
|
+
- examples/hello_world.rb
|
44
|
+
- lib/voke.rb
|
45
|
+
- lib/voke/version.rb
|
46
|
+
- test/voke_test.rb
|
47
|
+
- voke.gemspec
|
48
|
+
homepage: ''
|
49
|
+
licenses: []
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options: []
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ! '>='
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
requirements: []
|
67
|
+
rubyforge_project:
|
68
|
+
rubygems_version: 1.8.23
|
69
|
+
signing_key:
|
70
|
+
specification_version: 3
|
71
|
+
summary: Minimal CLI
|
72
|
+
test_files:
|
73
|
+
- test/voke_test.rb
|