-
-
Notifications
You must be signed in to change notification settings - Fork 540
/
new.rb
42 lines (33 loc) · 1.34 KB
/
new.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
require 'pathname'
require 'lotus/application_name'
require 'lotus/utils/string'
require 'lotus/utils/class'
module Lotus
module Commands
class New
GENERATORS_NAMESPACE = "Lotus::Generators::Application::%s".freeze
attr_reader :app_name, :source, :target, :cli, :options
def initialize(app_name_or_path, environment, cli)
@app_name = ApplicationName.new(_get_real_app_name(app_name_or_path))
@options = environment.to_options
@arch = @options.fetch(:architecture)
@target = Pathname.pwd.join(@options.fetch(:path, app_name_or_path))
@source = Pathname.new(@options.fetch(:source) { ::File.dirname(__FILE__) + '/../generators/application/' }).join(@arch)
@cli = cli
require "lotus/generators/application/#{ @arch }"
command = Utils::String.new(@arch).classify
@command = Utils::Class.load!(GENERATORS_NAMESPACE % command).new(self)
end
def start
@command.start
end
private
def _get_real_app_name(app_name_or_path)
if app_name_or_path.include?(::File::SEPARATOR)
raise ArgumentError.new("Invalid application name. If you want to set application path, please use --path option")
end
app_name_or_path == '.' ? ::File.basename(Dir.getwd) : app_name_or_path
end
end
end
end