lib/cf/cli/service/create.rb in cf-4.2.8.rc2 vs lib/cf/cli/service/create.rb in cf-4.2.8

- old
+ new

@@ -1,18 +1,8 @@ require "cf/cli/service/base" module CF::Service - USER_PROVIDED_OFFERING = "user-provided" # I'd rather move this to CFoundry - - class UPDummy - def label - "user-provided" - end - - attr_reader :version, :provider - end - class Create < Base offerings_from_label = proc { |label, offerings| offerings.select { |s| s.label == label } } @@ -54,94 +44,60 @@ end end end finalize - offerings << UPDummy.new - selected_offerings = offerings.any? ? Array(input[:offering, offerings.sort_by(&:label)]) : [] finalize if selected_offerings.empty? fail "Cannot find services matching the given criteria." end offering = selected_offerings.first - if offering.label == CF::Service::USER_PROVIDED_OFFERING - service_instance = client.user_provided_service_instance - service_instance.name = input[:name, offering] - finalize + service = client.service_instance + service.name = input[:name, offering] + finalize + plan = input[:plan, offering.service_plans] + finalize + service.service_plan = if plan.is_a?(String) + offering.service_plans.find { |p| p.name.casecmp(plan) == 0 } + else + plan + end + service.space = client.current_space - service_instance.credentials = ask_credentials # input[:credentials] - else - service_instance = client.service_instance - service_instance.name = input[:name, offering] - finalize - - plan = input[:plan, offering.service_plans] - finalize - service_instance.service_plan = if plan.is_a?(String) - offering.service_plans.find { |p| p.name.casecmp(plan) == 0 } - else - plan - end + with_progress("Creating service #{c(service.name, :name)}") do + service.create! end - service_instance.space = client.current_space - - with_progress("Creating service #{c(service_instance.name, :name)}") do - service_instance.create! - end - app = input[:app] finalize if app - invoke :bind_service, :service => service_instance, :app => app + invoke :bind_service, :service => service, :app => app end - service_instance + service end private - def ask_credentials - credentials = {} - line("What credentials parameters should applications use to connect to this service instance? (e.g. key: uri, value: mysql://username:password@hostname:port/name)") - - while true - key = ask("Key") - finalize - value = ask("Value") - finalize - credentials[key] = value - - break unless ask("Another credentials parameter?", :default => false) - end - - credentials - end - def ask_offering(offerings) [ask("What kind?", :choices => offerings.sort_by(&:label), - :display => proc do |s| + :display => proc { |s| str = "#{c(s.label, :name)} #{s.version}" if s.provider != "core" str << ", via #{s.provider}" end str - end, + }, :complete => proc { |s| "#{s.label} #{s.version}" })] end def ask_name(offering) - default = nil - unless offering == CF::Service::USER_PROVIDED_OFFERING - random = sprintf("%x", rand(1000000)) - default = "#{offering.label}-#{random}" - end - - ask "Name?", :default => default + random = sprintf("%x", rand(1000000)) + ask "Name?", :default => "#{offering.label}-#{random}" end def ask_plan(plans) ask "Which plan?", :choices => plans.sort_by(&:name),