19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/declare_schema/command.rb', line 19
def run(gem, args, version, **gemfile_options)
command = args.shift
case command
when nil
puts "\nThe command is missing!\n\n"
puts BANNER
exit(1)
when /^--help|-h$/
puts BANNER
exit
when 'new'
app_name = args.shift or begin
puts "\nThe application name is missing!\n\n"
puts BANNER
exit(1)
end
template_path = File.join(Dir.tmpdir, "declare_schema_app_template")
File.open(template_path, 'w') do |file|
file.puts ["gem '#{gem}', '>= #{version}'", (gemfile_options.inspect unless gemfile_options.empty?)].compact.join(', ')
end
puts "Generating Rails infrastructure..."
puts("rails new #{app_name} #{args * ' '} -m #{template_path}")
system("rails new #{app_name} #{args * ' '} -m #{template_path}")
File.delete(template_path)
when /^(g|generate|destroy)$/
cmd = Regexp.last_match(1)
if args.empty?
puts "\nThe generator name is missing!\n\n"
puts BANNER
exit(1)
else
system("bundle exec rails #{cmd} declare_schema:#{args * ' '}")
end
else
puts "\n => '#{command}' is an unknown command!\n\n"
puts BANNER
exit(1)
end
end
|