moses 0.1.8 → 0.1.9
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/VERSION +1 -1
- data/lib/moses/application.rb +4 -4
- data/lib/moses.rb +2 -2
- data/moses.gemspec +3 -4
- data/spec/application_spec.rb +4 -4
- data/spec/moses_spec.rb +16 -22
- metadata +3 -4
- data/test.rb +0 -27
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.9
|
data/lib/moses/application.rb
CHANGED
@@ -59,10 +59,9 @@ class Moses::Application
|
|
59
59
|
FileUtils.touch("#{@root_path}/#{@app_name}/bin/#{@app_name}")
|
60
60
|
FileUtils.chmod("u+x", "#{@root_path}/#{@app_name}/bin/#{@app_name}")
|
61
61
|
File.open("#{@root_path}/#{@app_name}/bin/#{@app_name}", 'w+') do |f|
|
62
|
-
f << %Q{
|
63
|
-
#!/usr/bin/env ruby
|
62
|
+
f << %Q{#!/usr/bin/env ruby
|
64
63
|
$: << File.expand_path(File.join(File.dirname(__FILE__), "../lib"))
|
65
|
-
require
|
64
|
+
require "#{@app_name}"
|
66
65
|
#{@app_name.camelize}.new.run
|
67
66
|
}
|
68
67
|
end
|
@@ -77,7 +76,8 @@ require '#{@app_name}'
|
|
77
76
|
unless File.file?("#{@root_path}/#{@app_name}/lib/#{@app_name}.rb")
|
78
77
|
FileUtils.touch("#{@root_path}/#{@app_name}/lib/#{@app_name}.rb")
|
79
78
|
File.open("#{@root_path}/#{@app_name}/lib/#{@app_name}.rb", 'w+') do |f|
|
80
|
-
f << %Q{
|
79
|
+
f << %Q{require "moses"
|
80
|
+
|
81
81
|
class #{@app_name.camelize}
|
82
82
|
include Moses
|
83
83
|
end
|
data/lib/moses.rb
CHANGED
@@ -69,7 +69,7 @@ module Moses
|
|
69
69
|
def parse_options
|
70
70
|
@args.each_with_index do |arg, index|
|
71
71
|
if flag?(arg)
|
72
|
-
#TODO split compound single dash flags
|
72
|
+
#TODO split compound single dash flags -abc
|
73
73
|
next_index = index + 1
|
74
74
|
if variable_option? index
|
75
75
|
create_variable_option(arg, next_index)
|
@@ -82,7 +82,7 @@ module Moses
|
|
82
82
|
end
|
83
83
|
|
84
84
|
def parse_command
|
85
|
-
unless default_command
|
85
|
+
unless default_command && @args.first == default_command
|
86
86
|
@command = @args.shift.to_sym if @args.first && @args.first.respond_to?(:to_sym)
|
87
87
|
end
|
88
88
|
end
|
data/moses.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "moses"
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.9"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Dayton Nolan"]
|
12
|
-
s.date = "2013-
|
12
|
+
s.date = "2013-10-17"
|
13
13
|
s.description = "Moses is a simple command parser for writing command line applications"
|
14
14
|
s.email = "daytonn@gmail.com"
|
15
15
|
s.executables = ["moses"]
|
@@ -35,8 +35,7 @@ Gem::Specification.new do |s|
|
|
35
35
|
"moses.png",
|
36
36
|
"spec/application_spec.rb",
|
37
37
|
"spec/moses_spec.rb",
|
38
|
-
"spec/spec_helper.rb"
|
39
|
-
"test.rb"
|
38
|
+
"spec/spec_helper.rb"
|
40
39
|
]
|
41
40
|
s.homepage = "http://github.com/daytonn/moses"
|
42
41
|
s.licenses = ["Apache 2.0"]
|
data/spec/application_spec.rb
CHANGED
@@ -54,10 +54,9 @@ describe Moses::Application do
|
|
54
54
|
it "makes an executable file" do
|
55
55
|
expect(File.file?("#{@tmp_dir}/test_app/bin/test_app")).to be_true
|
56
56
|
expect(File.executable?("#{@tmp_dir}/test_app/bin/test_app")).to be_true
|
57
|
-
expected_content = %Q{
|
58
|
-
#!/usr/bin/env ruby
|
57
|
+
expected_content = %Q{#!/usr/bin/env ruby
|
59
58
|
$: << File.expand_path(File.join(File.dirname(__FILE__), "../lib"))
|
60
|
-
require
|
59
|
+
require "test_app"
|
61
60
|
TestApp.new.run
|
62
61
|
}
|
63
62
|
expect(File.read("#{@tmp_dir}/test_app/bin/test_app")).to eq(expected_content)
|
@@ -69,7 +68,8 @@ TestApp.new.run
|
|
69
68
|
|
70
69
|
it "makes an applcation class file" do
|
71
70
|
expect(File.file?("#{@tmp_dir}/test_app/lib/test_app.rb")).to be_true
|
72
|
-
expected_content = %Q{
|
71
|
+
expected_content = %Q{require "moses"
|
72
|
+
|
73
73
|
class TestApp
|
74
74
|
include Moses
|
75
75
|
end
|
data/spec/moses_spec.rb
CHANGED
@@ -94,7 +94,7 @@ describe Moses do
|
|
94
94
|
|
95
95
|
describe "version_file_content" do
|
96
96
|
it "returns the contents of the VERSION file" do
|
97
|
-
|
97
|
+
stub_const("Moses::VERSION_FILE", "VERSION.test")
|
98
98
|
File.open('VERSION.test', 'w+') do |f|
|
99
99
|
f << 'x.x.x'
|
100
100
|
end
|
@@ -103,13 +103,13 @@ describe Moses do
|
|
103
103
|
end
|
104
104
|
|
105
105
|
it "outputs an instruction message when no VERSION file is present" do
|
106
|
-
|
106
|
+
stub_const("Moses::VERSION_FILE", "VERSION.test")
|
107
107
|
@output.should_receive(:puts).with("Include a VERSION file in your project or define a version method")
|
108
108
|
@app.send(:version)
|
109
109
|
end
|
110
110
|
|
111
111
|
it "returns the contents of the VERSION file" do
|
112
|
-
|
112
|
+
stub_const("Moses::VERSION_FILE", "VERSION.test")
|
113
113
|
File.open("VERSION.test", "w+") do |f|
|
114
114
|
f << 'x.x.x'
|
115
115
|
end
|
@@ -134,12 +134,6 @@ describe Moses do
|
|
134
134
|
expect(@dc_app.default_command).to eq(:some_command)
|
135
135
|
end
|
136
136
|
|
137
|
-
it "doesn't overwrite the default command when passed arguments" do
|
138
|
-
ARGV = ['test']
|
139
|
-
@dc_app.run
|
140
|
-
expect(@dc_app.command).to be_nil
|
141
|
-
expect(@dc_app.args.first).to eq('test')
|
142
|
-
end
|
143
137
|
end
|
144
138
|
|
145
139
|
describe 'option commands' do
|
@@ -176,7 +170,7 @@ describe Moses do
|
|
176
170
|
end
|
177
171
|
|
178
172
|
it "sets the command to the default option command if the default option is set" do
|
179
|
-
ARGV
|
173
|
+
stub_const("ARGV", ['-h'])
|
180
174
|
@app.run
|
181
175
|
expect(@app.command).to eq(:help)
|
182
176
|
end
|
@@ -188,7 +182,7 @@ describe Moses do
|
|
188
182
|
option_commands({ foo: :foo, v: :verbose })
|
189
183
|
end
|
190
184
|
@opt_cmd = OptionCommandsClass.new
|
191
|
-
ARGV
|
185
|
+
stub_const("ARGV", ['-v'])
|
192
186
|
@opt_cmd.run
|
193
187
|
expect(@opt_cmd.command).to eq(:verbose)
|
194
188
|
end
|
@@ -203,7 +197,7 @@ describe Moses do
|
|
203
197
|
|
204
198
|
describe "run" do
|
205
199
|
it "creates a local array of the ARGV array" do
|
206
|
-
ARGV
|
200
|
+
stub_const("ARGV", ['one', 'two', 'three'])
|
207
201
|
@app.stub(:parse_command)
|
208
202
|
@app.run
|
209
203
|
expect(@app.args).to eq(['one', 'two', 'three'])
|
@@ -211,7 +205,7 @@ describe Moses do
|
|
211
205
|
|
212
206
|
describe "command parsing" do
|
213
207
|
before do
|
214
|
-
ARGV
|
208
|
+
stub_const("ARGV", ['foo'])
|
215
209
|
@app.run
|
216
210
|
end
|
217
211
|
|
@@ -227,7 +221,7 @@ describe Moses do
|
|
227
221
|
describe "option parsing" do
|
228
222
|
describe "single dash flag" do
|
229
223
|
it "creates a boolean option with single dash flags -f" do
|
230
|
-
ARGV
|
224
|
+
stub_const("ARGV", ['foo', '-f'])
|
231
225
|
@app.run
|
232
226
|
expect(@app.options[:f]).to be_true
|
233
227
|
end
|
@@ -236,14 +230,14 @@ describe Moses do
|
|
236
230
|
describe 'double dash flag' do
|
237
231
|
|
238
232
|
it "removes the flags from the args array" do
|
239
|
-
ARGV
|
233
|
+
stub_const("ARGV", ['foo', '--flag', '-f'])
|
240
234
|
@app.run
|
241
235
|
expect(@app.args).to eq([])
|
242
236
|
end
|
243
237
|
|
244
238
|
context 'with value' do
|
245
239
|
it "creates a variable option" do
|
246
|
-
ARGV
|
240
|
+
stub_const("ARGV", ['foo', '--flag', 'value'])
|
247
241
|
@app.run
|
248
242
|
expect(@app.options[:flag]).to eq('value')
|
249
243
|
end
|
@@ -251,7 +245,7 @@ describe Moses do
|
|
251
245
|
|
252
246
|
context 'without value' do
|
253
247
|
it "creates a boolean option" do
|
254
|
-
ARGV
|
248
|
+
stub_const("ARGV", ['foo', '--flag'])
|
255
249
|
@app.run
|
256
250
|
expect(@app.options[:flag]).to be_true
|
257
251
|
end
|
@@ -261,29 +255,29 @@ describe Moses do
|
|
261
255
|
|
262
256
|
describe "running commands" do
|
263
257
|
it "sends the command if it is in the commands white list" do
|
264
|
-
ARGV
|
258
|
+
stub_const("ARGV", ['foo'])
|
265
259
|
@app.stub(:foo)
|
266
260
|
@app.should_receive(:foo)
|
267
261
|
@app.run
|
268
262
|
end
|
269
263
|
|
270
264
|
it "does not send a command if it is not in the commands white list" do
|
271
|
-
ARGV
|
265
|
+
stub_const("ARGV", ['baz'])
|
272
266
|
@app.should_not_receive(:baz)
|
273
267
|
@app.run
|
274
268
|
end
|
275
269
|
|
276
270
|
it "does not send a command if the method is not defined" do
|
277
|
-
ARGV
|
271
|
+
stub_const("ARGV", ['bar'])
|
278
272
|
@app.should_not_receive(:bar)
|
279
273
|
@app.run
|
280
274
|
end
|
281
275
|
|
282
276
|
it "runs any option commands if the option was passed" do
|
283
|
-
ARGV
|
277
|
+
stub_const("ARGV", ['-h'])
|
284
278
|
@app.should_receive(:help)
|
285
279
|
@app.run
|
286
280
|
end
|
287
281
|
end
|
288
282
|
end
|
289
|
-
end
|
283
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: moses
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-10-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -134,7 +134,6 @@ files:
|
|
134
134
|
- spec/application_spec.rb
|
135
135
|
- spec/moses_spec.rb
|
136
136
|
- spec/spec_helper.rb
|
137
|
-
- test.rb
|
138
137
|
homepage: http://github.com/daytonn/moses
|
139
138
|
licenses:
|
140
139
|
- Apache 2.0
|
@@ -150,7 +149,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
150
149
|
version: '0'
|
151
150
|
segments:
|
152
151
|
- 0
|
153
|
-
hash: -
|
152
|
+
hash: -2311972291789989622
|
154
153
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
155
154
|
none: false
|
156
155
|
requirements:
|
data/test.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
require 'pry'
|
2
|
-
|
3
|
-
module Foo
|
4
|
-
|
5
|
-
def self.included(base)
|
6
|
-
base.extend(ClassMethods)
|
7
|
-
end
|
8
|
-
|
9
|
-
module ClassMethods
|
10
|
-
def commands(*args)
|
11
|
-
class_eval %Q{
|
12
|
-
def commands
|
13
|
-
@commands ||= #{args}
|
14
|
-
end
|
15
|
-
}
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
class Bar
|
21
|
-
include Foo
|
22
|
-
|
23
|
-
commands :foo, :bar
|
24
|
-
end
|
25
|
-
|
26
|
-
b = Bar.new
|
27
|
-
puts b.commands
|