Sha256: 95741b3a442dd8c18c6bad061058c2c417f2895b344bd565bf836d0523c782a6

Contents?: true

Size: 1.69 KB

Versions: 55

Compression:

Stored size: 1.69 KB

Contents

require "cf/cli/start/base"
require "cf/cli/populators/target"

module CF::Start
  class Target < Base
    desc "Set or display the target cloud, organization, and space"
    group :start
    input :url, :desc => "Target URL to switch to", :argument => :optional
    input :organization, :desc => "Organization" , :aliases => %w{--org -o},
          :from_given => by_name(:organization)
    input :space, :desc => "Space", :alias => "-s",
          :from_given => by_name(:space)

    def target
      unless input.has?(:url) || input.has?(:organization) || \
              input.has?(:space)
        display_target
        display_org_and_space unless quiet?
        return
      end

      if input.has?(:url)
        target = sane_target_url(input[:url])
        with_progress("Setting target to #{c(target, :name)}") do
          begin
            CFoundry::Client.new(target) # check that it's valid before setting
          rescue CFoundry::TargetRefused
            fail "Target refused connection."
          rescue CFoundry::InvalidTarget
            fail "Invalid target URI."
          end

          set_target(target)
        end
      end

      return unless client.logged_in?

      if input.has?(:organization) || input.has?(:space)
        CF::Populators::Target.new(input).populate_and_save!
      end

      return if quiet?

      invalidate_client

      line
      display_target
      display_org_and_space
    end

    private

    def display_org_and_space
      if (org = client.current_organization)
        line "organization: #{c(org.name, :name)}"
      end

      if (space = client.current_space)
        line "space: #{c(space.name, :name)}"
      end
    rescue CFoundry::APIError
    end
  end
end

Version data entries

55 entries across 55 versions & 1 rubygems

Version Path
cf-4.1.5.rc6 lib/cf/cli/start/target.rb
cf-4.1.5.rc5 lib/cf/cli/start/target.rb
cf-4.1.5.rc4 lib/cf/cli/start/target.rb
cf-4.1.5.rc3 lib/cf/cli/start/target.rb
cf-4.1.5.rc2 lib/cf/cli/start/target.rb
cf-4.1.5.rc1 lib/cf/cli/start/target.rb
cf-4.1.4 lib/cf/cli/start/target.rb
cf-4.1.4.rc2 lib/cf/cli/start/target.rb
cf-4.1.4.rc1 lib/cf/cli/start/target.rb
cf-4.1.3 lib/cf/cli/start/target.rb
cf-4.1.2.rc2 lib/cf/cli/start/target.rb
cf-4.1.2.rc1 lib/cf/cli/start/target.rb
cf-4.1.1 lib/cf/cli/start/target.rb
cf-4.1.0rc2 lib/cf/cli/start/target.rb
cf-4.1.0rc1 lib/cf/cli/start/target.rb
cf-4.0.1.rc2 lib/cf/cli/start/target.rb
cf-4.0.1.rc1 lib/cf/cli/start/target.rb
cf-4.0.0rc2 lib/cf/cli/start/target.rb
cf-4.0.0rc1 lib/cf/cli/start/target.rb
cf-3.1.0rc2 lib/cf/cli/start/target.rb