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
|
# File 'lib/kumogata/template/ext/kumogata.rb', line 7
def init(stack_name)
begin
base_template = ''
File.open(Kumogata2::Client::get_template_path('_template'), 'r'){|f|
base_template = f.read
}
raise 'initialize template is empty' if base_template.empty?
new_template = "#{stack_name}.rb"
if File.exists? new_template
print "#{new_template} is already exists. Are sure want to overwrite? [y/N]: "
answer = STDIN.gets.to_s.chomp
return nil if answer.upcase != 'Y'
end
File.open(new_template, 'w'){|f|
template = base_template.gsub('#{NAME}', stack_name)
f.write(template)
}
Kumogata2::Logger::Helper.log(:info, "Saved template to #{stack_name}.rb".green)
rescue => e
Kumogata2::Logger::Helper.log(:error, "Failed to template #{stack_name} - #{e}".red)
end
nil
end
|