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
|
# File 'lib/greenhouse/tasks/add_project.rb', line 6
def prompt_for_project
remote = nil
print "Enter a git remote to add a project (leave blank to skip): "
remote = STDIN.gets.chomp
return if remote.empty?
project = Projects::Project.new(remote.match(/([^\/]*)\.git/)[1], {remote: remote})
if Projects::projects_file.projects.keys.include?(project.name) || Projects::projects_file.projects.values.map { |p| p['git'].downcase }.include?(project.repository.remote.downcase)
puts "Cannot add project. Another project with the same name already exists.".red
return
end
print "Enter a custom title for this project (leave blank for default) [#{project.title}]: "
title = STDIN.gets.chomp
project.title = title unless title.empty?
print "Is this project a 'gem', rails 'application', rails 'engine' or other type of project (leave blank to skip)?: "
type = STDIN.gets.chomp.downcase
type = 'application' if type == 'app' unless type.empty?
classname = "::Greenhouse::Projects::#{type.singularize.camelize}"
if defined?(classname.constantize)
project = classname.constantize.new(project.name, {remote: project.repository.remote, title: project.title})
puts "Configuring #{project.title} as #{type == 'gem' ? 'a' : 'an'} #{type}"
end
end
project
end
|