Sha256: 57ed353693fbf24211c9447eb1c27d6b6b2f63605ee40264724ca90d7973b7a2

Contents?: true

Size: 1.13 KB

Versions: 4

Compression:

Stored size: 1.13 KB

Contents

require "cf/detect"

require "cf/cli/service/base"

module CF::Service
  class Bind < Base
    desc "Bind a service to an application"
    group :services, :manage
    input :service, :desc => "Service to bind", :argument => :optional,
          :from_given => by_name(:service_instance, "service")
    input :app, :desc => "Application to bind to", :argument => :optional,
          :from_given => by_name(:app)
    def bind_service
      app = input[:app]
      service = input[:service, app]

      with_progress(
          "Binding #{c(service.name, :name)} to #{c(app.name, :name)}") do |s|
        if app.binds?(service)
          s.skip do
            err "App #{b(app.name)} already binds #{b(service.name)}."
          end
        else
          app.bind(service)
        end
      end
    end

    private

    def ask_service(app)
      services = client.service_instances
      fail "No services." if services.empty?

      ask "Which service?", :choices => services - app.services,
        :display => proc(&:name)
    end

    def ask_app
      ask "Which application?", :choices => client.apps,
        :display => proc(&:name)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cf-0.6.0.rc4 lib/cf/cli/service/bind.rb
cf-0.6.0.rc3 lib/cf/cli/service/bind.rb
cf-0.6.0.rc2 lib/cf/cli/service/bind.rb
cf-0.6.0.rc1 lib/cf/cli/service/bind.rb