lib/cf/cli/service/create.rb in cf-1.1.3.rc1 vs lib/cf/cli/service/create.rb in cf-1.1.4

- old
+ new

@@ -7,21 +7,22 @@ } desc "Create a service" group :services, :manage input :offering, :desc => "What kind of service (e.g. redis, mysql)", - :argument => :optional, :from_given => offerings_from_label + :argument => :optional, :from_given => offerings_from_label input :name, :desc => "Name for your service", :argument => :optional input :plan, :desc => "Service plan", - :from_given => find_by_name_insensitive("plan"), - :default => proc { - interact - } + :from_given => find_by_name_insensitive("plan"), + :default => proc { + interact + } input :provider, :desc => "Service provider" input :version, :desc => "Service version" input :app, :desc => "Application to immediately bind to", - :alias => "--bind", :from_given => by_name(:app) + :alias => "--bind", :from_given => by_name(:app) + def create_service offerings = client.services if input[:provider] offerings.reject! { |s| s.provider != input[:provider] } @@ -35,13 +36,13 @@ # string if the user provided it with a flag, or a ServicePlan if # something invoked this command with a particular plan if plan = input.direct(:plan) offerings.reject! do |s| if plan.is_a?(String) - s.service_plans.none? { |p| p.name == plan.upcase } + s.service_plans.none? { |p| p.name.casecmp(plan) == 0 } else - s.service_plans.include? plan + !s.service_plans.include? plan end end end selected_offerings = offerings.any? ? Array(input[:offering, offerings.sort_by(&:label)]) : [] @@ -53,11 +54,16 @@ offering = selected_offerings.first service = client.service_instance service.name = input[:name, offering] - service.service_plan = input[:plan, offering.service_plans] + plan = input[:plan, offering.service_plans] + 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 with_progress("Creating service #{c(service.name, :name)}") do service.create! end @@ -71,17 +77,17 @@ private def ask_offering(offerings) [ask("What kind?", :choices => offerings.sort_by(&:label), - :display => proc { |s| - str = "#{c(s.label, :name)} #{s.version}" - if s.provider != "core" - str << ", via #{s.provider}" - end - str - }, - :complete => proc { |s| "#{s.label} #{s.version}" })] + :display => proc { |s| + str = "#{c(s.label, :name)} #{s.version}" + if s.provider != "core" + str << ", via #{s.provider}" + end + str + }, + :complete => proc { |s| "#{s.label} #{s.version}" })] end def ask_name(offering) random = sprintf("%x", rand(1000000)) ask "Name?", :default => "#{offering.label}-#{random}"