moses 0.1.9 → 0.1.10
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.rb +33 -50
- data/lib/moses/application.rb +65 -48
- data/lib/moses/argument.rb +36 -0
- data/lib/moses/arguments.rb +34 -0
- data/moses.gemspec +14 -2
- data/spec/application_spec.rb +53 -70
- data/spec/argument_spec.rb +79 -0
- data/spec/arguments_spec.rb +50 -0
- data/spec/fixtures/HELP.md +1 -0
- data/spec/fixtures/VERSION +1 -0
- data/spec/fixtures/app_class.rb +5 -0
- data/spec/fixtures/bin_file +4 -0
- data/spec/moses_spec.rb +10 -7
- data/spec/spec_helper.rb +8 -1
- data/templates/HELP.md +1 -0
- data/templates/VERSION +1 -0
- data/templates/app_class.erb +5 -0
- data/templates/bin_file.erb +4 -0
- metadata +14 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.10
|
data/lib/moses.rb
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
$: << File.join(File.expand_path('../..', __FILE__), 'lib')
|
2
|
+
|
3
|
+
require "moses/argument"
|
4
|
+
require "moses/arguments"
|
5
|
+
|
1
6
|
module Moses
|
2
7
|
|
3
8
|
VERSION_FILE = 'VERSION'
|
@@ -55,88 +60,67 @@ module Moses
|
|
55
60
|
|
56
61
|
def run
|
57
62
|
@options = {}
|
58
|
-
@args =
|
63
|
+
@args = Moses::Arguments.new
|
59
64
|
parse_options
|
60
65
|
parse_command
|
61
66
|
set_option_command
|
62
67
|
|
63
|
-
|
64
|
-
|
68
|
+
if valid_command?
|
69
|
+
self.send(@command)
|
70
|
+
else
|
71
|
+
self.send(@default_command || :help)
|
72
|
+
end
|
65
73
|
end
|
66
74
|
|
67
75
|
private
|
68
76
|
|
69
77
|
def parse_options
|
70
|
-
|
71
|
-
if flag?
|
72
|
-
#TODO split compound single dash flags -abc
|
73
|
-
next_index = index + 1
|
74
|
-
if variable_option? index
|
75
|
-
create_variable_option(arg, next_index)
|
76
|
-
else
|
77
|
-
create_boolean_option(arg)
|
78
|
-
end
|
79
|
-
end
|
78
|
+
args.each do |arg|
|
79
|
+
@options[arg.to_sym] = args.get_variable(arg) if arg.flag?
|
80
80
|
end
|
81
|
-
@args.delete_if { |a| flag?(a) }
|
82
81
|
end
|
83
82
|
|
84
83
|
def parse_command
|
85
|
-
|
86
|
-
@command = @args.shift.to_sym if @args.first && @args.first.respond_to?(:to_sym)
|
87
|
-
end
|
84
|
+
@command = args.shift.to_sym if args.first && non_default_command?
|
88
85
|
end
|
89
86
|
|
90
87
|
def set_option_command
|
91
88
|
@options.each do |opt, v|
|
92
|
-
|
93
|
-
|
94
|
-
return
|
95
|
-
end
|
96
|
-
|
97
|
-
if default_option_commands[opt]
|
98
|
-
@command = default_option_commands[opt]
|
99
|
-
return
|
100
|
-
end
|
89
|
+
return @command = option_commands[opt] if has_option_command?(opt)
|
90
|
+
return @command = default_option_commands[opt] if default_option_commands[opt]
|
101
91
|
end
|
102
92
|
end
|
103
93
|
|
104
|
-
def
|
105
|
-
|
94
|
+
def default_command?
|
95
|
+
default_command && args.first == default_command
|
106
96
|
end
|
107
97
|
|
108
|
-
def
|
109
|
-
|
110
|
-
|
111
|
-
value = @args[next_index]
|
112
|
-
@args.delete_at next_index
|
113
|
-
end
|
98
|
+
def non_default_command?
|
99
|
+
!default_command?
|
100
|
+
end
|
114
101
|
|
115
|
-
|
102
|
+
def valid_command?
|
103
|
+
@command && default_commands.include?(@command) || has_command?(@command)
|
116
104
|
end
|
117
105
|
|
118
|
-
def
|
119
|
-
|
120
|
-
@options[key] = true
|
106
|
+
def has_commands?
|
107
|
+
self.class.method_defined?(:commands)
|
121
108
|
end
|
122
109
|
|
123
|
-
def
|
124
|
-
|
110
|
+
def has_command?(command)
|
111
|
+
has_commands? && [*commands].include?(command) && command_defined?(@command)
|
125
112
|
end
|
126
113
|
|
127
|
-
def
|
128
|
-
|
114
|
+
def command_defined?(commant)
|
115
|
+
self.class.method_defined?(command)
|
129
116
|
end
|
130
117
|
|
131
|
-
def
|
132
|
-
|
118
|
+
def has_option_commands?
|
119
|
+
self.class.method_defined?(:option_commands)
|
133
120
|
end
|
134
121
|
|
135
|
-
def
|
136
|
-
|
137
|
-
next_arg = @args[i+1]
|
138
|
-
#TODO: remove long_flag? check for short flag compatibility
|
139
|
-
long_flag?(arg) && next_arg && not_flag?(next_arg)
|
122
|
+
def has_option_command?(command)
|
123
|
+
has_option_commands? && !!option_commands[command]
|
140
124
|
end
|
141
125
|
|
142
126
|
def help
|
@@ -157,5 +141,4 @@ module Moses
|
|
157
141
|
content = File.read(File.expand_path(Moses::VERSION_FILE)) if File.exist?(File.expand_path(Moses::VERSION_FILE))
|
158
142
|
content
|
159
143
|
end
|
160
|
-
|
161
144
|
end
|
data/lib/moses/application.rb
CHANGED
@@ -1,25 +1,25 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "moses"
|
2
|
+
require "fileutils"
|
3
|
+
require "erb"
|
4
|
+
require "active_support/inflector"
|
4
5
|
|
5
6
|
class Moses::Application
|
6
7
|
include Moses
|
7
8
|
commands :create
|
8
|
-
attr_reader :root_path
|
9
|
+
attr_reader :root_path, :app_name
|
9
10
|
|
10
11
|
def initialize(root_path = Dir.getwd)
|
11
12
|
@root_path = root_path
|
12
13
|
end
|
13
14
|
|
14
15
|
def create
|
15
|
-
if @args.first
|
16
|
-
@app_name = @args.first
|
16
|
+
if @app_name = args.first
|
17
17
|
create_app_dir
|
18
|
+
create_bin_dir
|
19
|
+
create_lib_dir
|
18
20
|
create_help_file
|
19
21
|
create_version_file
|
20
|
-
create_bin_dir
|
21
22
|
create_bin_file
|
22
|
-
create_lib_dir
|
23
23
|
create_application_class
|
24
24
|
else
|
25
25
|
output.puts "You need to name your application: moses create myapp"
|
@@ -29,60 +29,77 @@ class Moses::Application
|
|
29
29
|
private
|
30
30
|
|
31
31
|
def create_app_dir
|
32
|
-
|
32
|
+
create_directory(app_dir)
|
33
|
+
end
|
34
|
+
|
35
|
+
def create_bin_dir
|
36
|
+
create_directory(bin_dir)
|
37
|
+
end
|
38
|
+
|
39
|
+
def create_lib_dir
|
40
|
+
FileUtils.mkdir(lib_dir) unless File.directory?(lib_dir)
|
33
41
|
end
|
34
42
|
|
35
43
|
def create_help_file
|
36
|
-
|
37
|
-
FileUtils.touch("#{@root_path}/#{@app_name}/HELP.md")
|
38
|
-
File.open("#{@root_path}/#{@app_name}/HELP.md", 'w+') do |f|
|
39
|
-
f << "Todo: Add your own instructions"
|
40
|
-
end
|
41
|
-
end
|
44
|
+
copy_template("HELP.md", help_file)
|
42
45
|
end
|
43
46
|
|
44
47
|
def create_version_file
|
45
|
-
|
46
|
-
FileUtils.touch("#{@root_path}/#{@app_name}/VERSION")
|
47
|
-
File.open("#{@root_path}/#{@app_name}/VERSION", 'w+') do |f|
|
48
|
-
f << "0.0.0"
|
49
|
-
end
|
50
|
-
end
|
48
|
+
copy_template("VERSION", version_file)
|
51
49
|
end
|
52
50
|
|
53
|
-
def
|
54
|
-
|
51
|
+
def create_bin_file
|
52
|
+
unless File.file?(bin_file)
|
53
|
+
bin_template = ERB.new(File.read(template("bin_file.erb")))
|
54
|
+
File.open(bin_file, "w+") { |f| f << bin_template.result(binding) }
|
55
|
+
FileUtils.chmod("u+x", bin_file)
|
56
|
+
end
|
55
57
|
end
|
56
58
|
|
57
|
-
def
|
58
|
-
unless File.file?(
|
59
|
-
|
60
|
-
|
61
|
-
File.open("#{@root_path}/#{@app_name}/bin/#{@app_name}", 'w+') do |f|
|
62
|
-
f << %Q{#!/usr/bin/env ruby
|
63
|
-
$: << File.expand_path(File.join(File.dirname(__FILE__), "../lib"))
|
64
|
-
require "#{@app_name}"
|
65
|
-
#{@app_name.camelize}.new.run
|
66
|
-
}
|
67
|
-
end
|
59
|
+
def create_application_class
|
60
|
+
unless File.file?(app_class_file)
|
61
|
+
class_template = ERB.new(File.read(template("app_class.erb")))
|
62
|
+
File.open(app_class_file, 'w+') { |f| f << class_template.result(binding) }
|
68
63
|
end
|
69
64
|
end
|
70
65
|
|
71
|
-
def
|
72
|
-
|
66
|
+
def app_dir
|
67
|
+
File.join(root_path, app_name)
|
73
68
|
end
|
74
69
|
|
75
|
-
def
|
76
|
-
|
77
|
-
|
78
|
-
File.open("#{@root_path}/#{@app_name}/lib/#{@app_name}.rb", 'w+') do |f|
|
79
|
-
f << %Q{require "moses"
|
70
|
+
def bin_dir
|
71
|
+
File.join(app_dir, "bin")
|
72
|
+
end
|
80
73
|
|
81
|
-
|
82
|
-
|
83
|
-
end
|
84
|
-
|
85
|
-
|
86
|
-
|
74
|
+
def lib_dir
|
75
|
+
File.join(app_dir, "lib")
|
76
|
+
end
|
77
|
+
|
78
|
+
def help_file
|
79
|
+
File.join(app_dir, "HELP.md")
|
80
|
+
end
|
81
|
+
|
82
|
+
def version_file
|
83
|
+
File.join(app_dir, "VERSION")
|
84
|
+
end
|
85
|
+
|
86
|
+
def bin_file
|
87
|
+
File.join(bin_dir, app_name)
|
87
88
|
end
|
88
|
-
|
89
|
+
|
90
|
+
def app_class_file
|
91
|
+
File.join(lib_dir, "#{app_name}.rb")
|
92
|
+
end
|
93
|
+
|
94
|
+
def template(filename)
|
95
|
+
File.join(File.dirname(File.expand_path("../..", __FILE__)), "templates", filename)
|
96
|
+
end
|
97
|
+
|
98
|
+
def copy_template(src, dest)
|
99
|
+
FileUtils.cp(template(src), dest) unless File.file?(dest)
|
100
|
+
end
|
101
|
+
|
102
|
+
def create_directory(dir)
|
103
|
+
FileUtils.mkdir(dir) unless File.directory?(dir)
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Moses
|
2
|
+
class Argument < String
|
3
|
+
|
4
|
+
attr_accessor :value
|
5
|
+
|
6
|
+
def initialize(string)
|
7
|
+
@value = string
|
8
|
+
super(string)
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_s
|
12
|
+
value
|
13
|
+
end
|
14
|
+
|
15
|
+
def flag?
|
16
|
+
self =~ /^-/ ? true : false
|
17
|
+
end
|
18
|
+
|
19
|
+
def short_flag?
|
20
|
+
self =~ /^-{1}[^-]/ ? true : false
|
21
|
+
end
|
22
|
+
|
23
|
+
def long_flag?
|
24
|
+
self =~ /^-{2}/ ? true : false
|
25
|
+
end
|
26
|
+
|
27
|
+
def not_flag?
|
28
|
+
!flag?
|
29
|
+
end
|
30
|
+
|
31
|
+
def to_sym
|
32
|
+
value.gsub(/^-{1,2}/, '').to_sym
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
class Moses::Arguments < Array
|
2
|
+
attr_reader :variables
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
@variables = {}
|
6
|
+
super(args)
|
7
|
+
end
|
8
|
+
|
9
|
+
def has_variable?(arg)
|
10
|
+
return true if variables[arg]
|
11
|
+
next_index = self.index(arg) + 1
|
12
|
+
next_arg = self[next_index]
|
13
|
+
#TODO: remove long_flag? check for short flag compatibility
|
14
|
+
arg.long_flag? && next_arg && next_arg.not_flag?
|
15
|
+
end
|
16
|
+
|
17
|
+
def get_variable(arg)
|
18
|
+
return variables[arg] if variables[arg]
|
19
|
+
if has_variable?(arg) || arg.flag?
|
20
|
+
next_arg = self[self.index(arg) + 1]
|
21
|
+
value = next_arg || true
|
22
|
+
@variables[arg] ||= value
|
23
|
+
self.delete_at(self.index(next_arg)) if next_arg
|
24
|
+
self.delete_at self.index(arg)
|
25
|
+
variables[arg]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def args
|
32
|
+
Array.try_convert(ARGV).map { |arg| Moses::Argument.new(arg) }
|
33
|
+
end
|
34
|
+
end
|
data/moses.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "moses"
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.10"
|
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"]
|
@@ -31,11 +31,23 @@ Gem::Specification.new do |s|
|
|
31
31
|
"bin/moses",
|
32
32
|
"lib/moses.rb",
|
33
33
|
"lib/moses/application.rb",
|
34
|
+
"lib/moses/argument.rb",
|
35
|
+
"lib/moses/arguments.rb",
|
34
36
|
"moses.gemspec",
|
35
37
|
"moses.png",
|
36
38
|
"spec/application_spec.rb",
|
39
|
+
"spec/argument_spec.rb",
|
40
|
+
"spec/arguments_spec.rb",
|
41
|
+
"spec/fixtures/HELP.md",
|
42
|
+
"spec/fixtures/VERSION",
|
43
|
+
"spec/fixtures/app_class.rb",
|
44
|
+
"spec/fixtures/bin_file",
|
37
45
|
"spec/moses_spec.rb",
|
38
|
-
"spec/spec_helper.rb"
|
46
|
+
"spec/spec_helper.rb",
|
47
|
+
"templates/HELP.md",
|
48
|
+
"templates/VERSION",
|
49
|
+
"templates/app_class.erb",
|
50
|
+
"templates/bin_file.erb"
|
39
51
|
]
|
40
52
|
s.homepage = "http://github.com/daytonn/moses"
|
41
53
|
s.licenses = ["Apache 2.0"]
|
data/spec/application_spec.rb
CHANGED
@@ -3,89 +3,72 @@ require 'moses/application'
|
|
3
3
|
require 'pry'
|
4
4
|
|
5
5
|
describe Moses::Application do
|
6
|
+
let(:tmp_dir) { Dir.mktmpdir }
|
7
|
+
let(:app_dir) { File.join(tmp_dir, "test_app") }
|
8
|
+
let(:lib_dir) { File.join(app_dir, "lib") }
|
9
|
+
let(:bin_dir) { File.join(app_dir, "bin") }
|
10
|
+
let(:help_file) { File.join(app_dir, "HELP.md") }
|
11
|
+
let(:version_file) { File.join(app_dir, "VERSION") }
|
12
|
+
let(:bin_file) { File.join(bin_dir, "test_app") }
|
13
|
+
let(:app_class_file) { File.join(lib_dir, "test_app.rb") }
|
14
|
+
subject { Moses::Application.new tmp_dir }
|
15
|
+
|
16
|
+
after do
|
17
|
+
FileUtils.rm_rf tmp_dir
|
18
|
+
end
|
6
19
|
|
7
|
-
describe "
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
@tmp_dir = Dir.mktmpdir
|
12
|
-
@app = Moses::Application.new @tmp_dir
|
20
|
+
describe "initialization" do
|
21
|
+
it "has default root_path" do
|
22
|
+
subject = Moses::Application.new
|
23
|
+
expect(subject.root_path).to eq(File.dirname(File.expand_path('..', __FILE__)))
|
13
24
|
end
|
14
25
|
|
15
|
-
|
16
|
-
|
26
|
+
it "can be initialized with a root_path" do
|
27
|
+
expect(subject.root_path).to eq(tmp_dir)
|
17
28
|
end
|
29
|
+
end
|
18
30
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end
|
24
|
-
|
25
|
-
it "can be initialized with a root_path" do
|
26
|
-
expect(@app.root_path).to eq(@tmp_dir)
|
27
|
-
end
|
31
|
+
describe "create" do
|
32
|
+
before do
|
33
|
+
subject.instance_variable_set(:@args, ['test_app'])
|
34
|
+
subject.create
|
28
35
|
end
|
29
36
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
@app.create
|
34
|
-
end
|
35
|
-
|
36
|
-
it "makes a directory for the application" do
|
37
|
-
expect(File.directory?("#{@tmp_dir}/test_app")).to be_true
|
38
|
-
end
|
39
|
-
|
40
|
-
it "makes a HELP file" do
|
41
|
-
expect(File.file?("#{@tmp_dir}/test_app/HELP.md")).to be_true
|
42
|
-
expect(File.read("#{@tmp_dir}/test_app/HELP.md")).to eq("Todo: Add your own instructions")
|
43
|
-
end
|
44
|
-
|
45
|
-
it "makes a version file" do
|
46
|
-
expect(File.file?("#{@tmp_dir}/test_app/VERSION")).to be_true
|
47
|
-
expect(File.read("#{@tmp_dir}/test_app/VERSION")).to eq("0.0.0")
|
48
|
-
end
|
37
|
+
it "makes a directory for the application" do
|
38
|
+
expect(File.directory?(app_dir)).to be_true
|
39
|
+
end
|
49
40
|
|
50
|
-
|
51
|
-
|
52
|
-
|
41
|
+
it "makes a HELP file" do
|
42
|
+
expect(File.read(help_file)).to eq(fixture_content("HELP.md"))
|
43
|
+
end
|
53
44
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
expected_content = %Q{#!/usr/bin/env ruby
|
58
|
-
$: << File.expand_path(File.join(File.dirname(__FILE__), "../lib"))
|
59
|
-
require "test_app"
|
60
|
-
TestApp.new.run
|
61
|
-
}
|
62
|
-
expect(File.read("#{@tmp_dir}/test_app/bin/test_app")).to eq(expected_content)
|
63
|
-
end
|
45
|
+
it "makes a version file" do
|
46
|
+
expect(File.read(version_file)).to eq(fixture_content("VERSION"))
|
47
|
+
end
|
64
48
|
|
65
|
-
|
66
|
-
|
67
|
-
|
49
|
+
it "makes a bin directory" do
|
50
|
+
expect(File.directory?(bin_dir)).to be_true
|
51
|
+
end
|
68
52
|
|
69
|
-
|
70
|
-
|
71
|
-
|
53
|
+
it "makes an executable file" do
|
54
|
+
expect(File.read(bin_file)).to eq(fixture_content("bin_file"))
|
55
|
+
expect(File.executable?(bin_file)).to be_true
|
56
|
+
end
|
72
57
|
|
73
|
-
|
74
|
-
|
75
|
-
end
|
76
|
-
}
|
77
|
-
expect(File.read("#{@tmp_dir}/test_app/lib/test_app.rb")).to eq(expected_content)
|
78
|
-
end
|
58
|
+
it "makes a lib directory" do
|
59
|
+
expect(File.directory?(lib_dir)).to be_true
|
60
|
+
end
|
79
61
|
|
80
|
-
|
81
|
-
|
82
|
-
app.instance_variable_set(:@args, [])
|
83
|
-
app.output.stub(:puts)
|
84
|
-
app.output.should_receive(:puts).with('You need to name your application: moses create myapp')
|
85
|
-
app.create
|
86
|
-
end
|
62
|
+
it "makes an applcation class file" do
|
63
|
+
expect(File.read(app_class_file)).to eq(fixture_content("app_class.rb"))
|
87
64
|
end
|
88
65
|
|
66
|
+
it "warns you if you forget the app name" do
|
67
|
+
app = Moses::Application.new
|
68
|
+
app.instance_variable_set(:@args, [])
|
69
|
+
app.output.stub(:puts)
|
70
|
+
app.output.should_receive(:puts).with('You need to name your application: moses create myapp')
|
71
|
+
app.create
|
72
|
+
end
|
89
73
|
end
|
90
|
-
|
91
|
-
end
|
74
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'moses/argument'
|
3
|
+
|
4
|
+
describe Moses::Argument do
|
5
|
+
|
6
|
+
it "takes a string" do
|
7
|
+
expect { Moses::Argument.new }.to raise_error ArgumentError
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "flags" do
|
11
|
+
let(:short_flag) { Moses::Argument.new '-f' }
|
12
|
+
let(:long_flag) { Moses::Argument.new '--long_flag' }
|
13
|
+
let(:non_flag) { Moses::Argument.new 'test' }
|
14
|
+
|
15
|
+
it "determines if the argument is a flag" do
|
16
|
+
expect(short_flag).to be_flag
|
17
|
+
expect(long_flag).to be_flag
|
18
|
+
expect(non_flag).not_to be_flag
|
19
|
+
end
|
20
|
+
|
21
|
+
it "determines if the argument is a short flag" do
|
22
|
+
expect(short_flag).to be_short_flag
|
23
|
+
|
24
|
+
expect(long_flag).not_to be_short_flag
|
25
|
+
expect(non_flag).not_to be_short_flag
|
26
|
+
end
|
27
|
+
|
28
|
+
it "determines if the argument is a long flag" do
|
29
|
+
expect(long_flag).to be_long_flag
|
30
|
+
|
31
|
+
expect(short_flag).not_to be_long_flag
|
32
|
+
expect(non_flag).not_to be_long_flag
|
33
|
+
end
|
34
|
+
|
35
|
+
it "determine if the argument is not a flag" do
|
36
|
+
expect(long_flag).not_to be_not_flag
|
37
|
+
expect(short_flag).not_to be_not_flag
|
38
|
+
expect(non_flag).to be_not_flag
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "to_sym" do
|
42
|
+
it "removes the dashes prepending flags" do
|
43
|
+
expect(short_flag.to_sym).to eq(:f)
|
44
|
+
expect(long_flag.to_sym).to eq(:long_flag)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "converts plain args to symbol" do
|
48
|
+
expect(non_flag.to_sym).to eq(:test)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "value" do
|
54
|
+
before do
|
55
|
+
@arg = Moses::Argument.new 'test'
|
56
|
+
end
|
57
|
+
|
58
|
+
it "can be assigned a value" do
|
59
|
+
@arg.value = 'foo'
|
60
|
+
expect(@arg.value).to eq('foo')
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "to_s" do
|
65
|
+
before do
|
66
|
+
@arg = Moses::Argument.new 'test'
|
67
|
+
end
|
68
|
+
|
69
|
+
it "renders the original string if there is no value" do
|
70
|
+
expect(@arg.to_s).to eq('test')
|
71
|
+
end
|
72
|
+
|
73
|
+
it "renders the value when set" do
|
74
|
+
@arg.value = 'foo'
|
75
|
+
expect(@arg.to_s).to eq('foo')
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'moses/arguments'
|
3
|
+
|
4
|
+
describe Moses::Arguments do
|
5
|
+
before do
|
6
|
+
stub_const("ARGV", ["-f", "--long-flag", "test"])
|
7
|
+
end
|
8
|
+
|
9
|
+
subject { Moses::Arguments.new }
|
10
|
+
|
11
|
+
it "creates an array of arguments" do
|
12
|
+
expect(subject.first).to be_flag
|
13
|
+
expect(subject.first).to be_short_flag
|
14
|
+
expect(subject[1]).to be_flag
|
15
|
+
expect(subject[1]).to be_long_flag
|
16
|
+
expect(subject.last).not_to be_flag
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "has_variable?" do
|
20
|
+
it "returns true if the next argument exists and is not a flag" do
|
21
|
+
expect(subject.has_variable?(subject[1])).to be_true
|
22
|
+
end
|
23
|
+
|
24
|
+
it "returns false if the argument is not a flag" do
|
25
|
+
expect(subject.has_variable?(subject.last)).to be_false
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "get_variable" do
|
30
|
+
it "returns the next argument" do
|
31
|
+
expect(subject.get_variable(subject[1])).to eq("test")
|
32
|
+
end
|
33
|
+
|
34
|
+
it "removes the variable from the arguments" do
|
35
|
+
subject.get_variable(subject[1])
|
36
|
+
expect(subject.last).not_to include("--long-flag")
|
37
|
+
end
|
38
|
+
|
39
|
+
it "caches the variable value" do
|
40
|
+
flag = subject[1].to_s
|
41
|
+
subject.get_variable(subject[1])
|
42
|
+
expect(subject).not_to include("--long-flag")
|
43
|
+
expect(subject.get_variable(flag)).to eq("test")
|
44
|
+
end
|
45
|
+
|
46
|
+
it "returns true if there is no value" do
|
47
|
+
expect(subject.get_variable(subject.first)).to be_true
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
Todo: Add your own instructions
|
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
data/spec/moses_spec.rb
CHANGED
@@ -17,10 +17,6 @@ describe Moses do
|
|
17
17
|
@app = TestAppClass.new(@output)
|
18
18
|
end
|
19
19
|
|
20
|
-
after do
|
21
|
-
ARGV.clear
|
22
|
-
end
|
23
|
-
|
24
20
|
describe 'output' do
|
25
21
|
it "defaults to STDOUT" do
|
26
22
|
class TestOutputAppClass
|
@@ -133,7 +129,6 @@ describe Moses do
|
|
133
129
|
it "can be set with the class method" do
|
134
130
|
expect(@dc_app.default_command).to eq(:some_command)
|
135
131
|
end
|
136
|
-
|
137
132
|
end
|
138
133
|
|
139
134
|
describe 'option commands' do
|
@@ -153,8 +148,12 @@ describe Moses do
|
|
153
148
|
class OptionCommandsClass
|
154
149
|
include Moses
|
155
150
|
option_commands({ foo: :foo, v: :verbose })
|
151
|
+
|
152
|
+
def initialize(output)
|
153
|
+
@output = output
|
154
|
+
end
|
156
155
|
end
|
157
|
-
@opt_cmd = OptionCommandsClass.new
|
156
|
+
@opt_cmd = OptionCommandsClass.new(@output)
|
158
157
|
|
159
158
|
expect(@opt_cmd.option_commands).to have_key(:foo)
|
160
159
|
expect(@opt_cmd.option_commands).to have_key(:h)
|
@@ -180,8 +179,12 @@ describe Moses do
|
|
180
179
|
include Moses
|
181
180
|
commands :verbose
|
182
181
|
option_commands({ foo: :foo, v: :verbose })
|
182
|
+
|
183
|
+
def initialize(output)
|
184
|
+
@output = output
|
185
|
+
end
|
183
186
|
end
|
184
|
-
@opt_cmd = OptionCommandsClass.new
|
187
|
+
@opt_cmd = OptionCommandsClass.new(@output)
|
185
188
|
stub_const("ARGV", ['-v'])
|
186
189
|
@opt_cmd.run
|
187
190
|
expect(@opt_cmd.command).to eq(:verbose)
|
data/spec/spec_helper.rb
CHANGED
@@ -11,4 +11,11 @@ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
|
11
11
|
|
12
12
|
RSpec.configure do |config|
|
13
13
|
|
14
|
-
|
14
|
+
def fixture(file)
|
15
|
+
File.join(File.expand_path("../", __FILE__), "fixtures", file)
|
16
|
+
end
|
17
|
+
|
18
|
+
def fixture_content(file)
|
19
|
+
File.read(fixture(file))
|
20
|
+
end
|
21
|
+
end
|
data/templates/HELP.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Todo: Add your own instructions
|
data/templates/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
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.10
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -129,11 +129,23 @@ files:
|
|
129
129
|
- bin/moses
|
130
130
|
- lib/moses.rb
|
131
131
|
- lib/moses/application.rb
|
132
|
+
- lib/moses/argument.rb
|
133
|
+
- lib/moses/arguments.rb
|
132
134
|
- moses.gemspec
|
133
135
|
- moses.png
|
134
136
|
- spec/application_spec.rb
|
137
|
+
- spec/argument_spec.rb
|
138
|
+
- spec/arguments_spec.rb
|
139
|
+
- spec/fixtures/HELP.md
|
140
|
+
- spec/fixtures/VERSION
|
141
|
+
- spec/fixtures/app_class.rb
|
142
|
+
- spec/fixtures/bin_file
|
135
143
|
- spec/moses_spec.rb
|
136
144
|
- spec/spec_helper.rb
|
145
|
+
- templates/HELP.md
|
146
|
+
- templates/VERSION
|
147
|
+
- templates/app_class.erb
|
148
|
+
- templates/bin_file.erb
|
137
149
|
homepage: http://github.com/daytonn/moses
|
138
150
|
licenses:
|
139
151
|
- Apache 2.0
|
@@ -149,7 +161,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
149
161
|
version: '0'
|
150
162
|
segments:
|
151
163
|
- 0
|
152
|
-
hash: -
|
164
|
+
hash: -782149874881107108
|
153
165
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
166
|
none: false
|
155
167
|
requirements:
|