Class: EPC::Command::CreateProjectCommand
- Inherits:
-
BaseCommand
- Object
- BaseCommand
- EPC::Command::CreateProjectCommand
- Defined in:
- lib/epc/command/project/create_project_command.rb
Constant Summary
Constants inherited from BaseCommand
BaseCommand::GIVEUP_TICKS, BaseCommand::SLEEP_TIME, BaseCommand::TICKER_TICKS
Instance Attribute Summary
Attributes inherited from BaseCommand
#client, #klass_name, #object_id, #object_type, #options, #target_id, #target_type
Instance Method Summary collapse
Methods inherited from BaseCommand
#check_options, #context_params, #context_params=, #go, include_module, inherited, #initialize, required_options, #say_err
Methods included from PersistentAttributes
#auth_token, #caller_id, #target_url
Constructor Details
This class inherits a constructor from EPC::Command::BaseCommand
Instance Method Details
#execute(params = []) ⇒ Object
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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/epc/command/project/create_project_command.rb', line 3 def execute(params = []) project_name = params[0] uri_name = params[1] memory = params[2] raise FatalError, "You have to specify a project name to run this command" if project_name.blank? raise InputError, "Target type must be: [Solution]" if target_type.present? && target_type.downcase != "solution" if numeric?(@options[:type]) type_id = @options[:type].to_i elsif @options[:type].present? type_id = get_resource_id(EPC::Config::PROJECT_TYPES_PATH, :name, @options[:type], :case_sensitivity => false) end if type_id.blank? || type_id == 0 choose do || .prompt = "Please choose the project type: " status, response, headers = client.get(EPC::Config::PROJECT_TYPES_PATH) if status.failure? say("Request failed: [#{response[:message]}") return status end if response.empty? say("No project types defined yet") return status end response.each do |type| .choice(type[:name]) { type_id = type[:id]} end end end path = File.(".") solution_id, solution_name = infer_solution_context(target_id, path, :get_solution_name => true) raise InputError, "Request failed: [Solution not found]" if solution_name.nil? uri_name = project_name if uri_name.nil? proceed = ask_yn("You are creating the '#{project_name}' project as part of the '#{solution_name}' solution. Correct? [Yn]: ") if proceed.upcase == 'N' return 1 end begin status, response, headers = client.post("#{EPC::Config::PROJECTS_PATH}", { :name => project_name, :solution_name => solution_name, :uri_name => uri_name, :project_type_id => type_id, :runtime_memory => memory}) if status.successful? if [:nodir] say("Successfully created the project with [#{target_url}]") return status end result = mkdir(project_name) if result == :ok EPC::Config.(response[:id], client) say("Successfully created the project with [#{target_url}] and created your local directory.") else say("Successfully created the project with [#{target_url}], but FAILED to create your local directory.") end else say_err("Project creation failed [#{response[:message]}].") end rescue Exception => ex say_err("Project creation failed [#{ex}].") return 1 end return status end |