vmc-ng/lib/vmc/cli/service.rb in vmc-0.4.0.beta.23 vs vmc-ng/lib/vmc/cli/service.rb in vmc-0.4.0.beta.24

- old
+ new

@@ -28,20 +28,32 @@ instances = with_progress("Getting service instances") do client.service_instances(2) end + line unless quiet? + if instances.empty? and !quiet? - puts "" - puts "No services." + line "No services." end - instances.each.with_index do |i, n| - display_instance(i) if instance_matches(i, input) + spaced(instances) do |i| + display_service_instance(i) if instance_matches(i, input) end end + + desc "Show service instance information" + group :services + input :instance, :argument => :required, + :from_given => by_name("service instance", :service_instance), + :desc => "Service instance to show" + def service(input) + display_service_instance(input[:instance]) + end + + services_from_label = proc { |label, services| services.select { |s| s.label == label } } desc "Create a service" @@ -87,13 +99,23 @@ if input[:version] services.reject! { |s| s.version != input[:version] } end + if plan = input.given(:plan) + services.reject! { |s| + if plan.is_a?(String) + s.service_plans.none? { |p| p.name == plan.upcase } + else + s.service_plans.include? plan + end + } + end + until services.size < 2 # cast to Array since it might be given as a Service with #invoke - services = Array(input[:service, services]) + services = Array(input[:service, services.sort_by(&:label)]) input.forget(:service) end if services.empty? fail "Cannot find services matching the given criteria." @@ -128,11 +150,11 @@ desc "Bind a service instance to an application" group :services, :manage input(:instance, :argument => true, - :from_given => by_name("instance", :service_instance), + :from_given => by_name("service instance", :service_instance), :desc => "Service to bind") { |app| instances = client.service_instances fail "No service instances." if instances.empty? ask "Which service instance?", @@ -163,24 +185,24 @@ desc "Unbind a service from an application" group :services, :manage input(:instance, :argument => true, - :from_given => find_by_name("instance"), - :desc => "Service to bind") { |instances| - ask "Which service instance?", :choices => instances, + :from_given => find_by_name("service instance"), + :desc => "Service to bind") { |app| + ask "Which service instance?", :choices => app.services, :display => proc(&:name) } input(:app, :argument => true, :from_given => find_by_name("app"), - :desc => "Application to bind to") { |apps| - ask "Which application?", :choices => apps, + :desc => "Application to bind to") { + ask "Which application?", :choices => client.apps(2), :display => proc(&:name) } def unbind_service(input) - app = input[:app, client.apps(2)] - instance = input[:instance, app.services] + app = input[:app] + instance = input[:instance, app] with_progress( "Unbinding #{c(instance.name, :name)} from #{c(app.name, :name)}") do app.unbind(instance) end @@ -188,12 +210,15 @@ desc "Delete a service" group :services, :manage input(:instance, :argument => true, - :from_given => find_by_name("instance"), - :desc => "Service to bind") { |instances| + :from_given => by_name("service instance", :service_instance), + :desc => "Service to bind") { + instances = client.service_instances + fail "No services." if instances.empty? + ask "Which service instance?", :choices => instances, :display => proc(&:name) } input(:really, :type => :boolean, :forget => true) { |name, color| force? || ask("Really delete #{c(name, color)}?", :default => false) @@ -208,15 +233,12 @@ end return end - instances = client.service_instances - fail "No services." if instances.empty? + instance = input[:instance] - instance = input[:instance, instances] - return unless input[:really, instance.name, :name] with_progress("Deleting #{c(instance.name, :name)}") do |s| bindings = instance.service_bindings @@ -257,21 +279,26 @@ end true end - def display_instance(i) + def display_service_instance(i) if quiet? - puts i.name + line i.name else plan = i.service_plan service = plan.service - puts "" - puts "#{c(i.name, :name)}: #{service.label} #{service.version}" - puts " description: #{service.description}" - puts " plan: #{c(plan.name, :name)}" - puts " description: #{plan.description}" + line "#{c(i.name, :name)}: #{service.label} #{service.version}" + + indented do + line "description: #{service.description}" + line "plan: #{c(plan.name, :name)}" + + indented do + line "description: #{plan.description}" + end + end end end def human_list(xs) if xs.size == 1