Sha256: 4a4344b565a0fea80766d0015b49a3e8bcc3266a2a51f1c90a3d67fcf2bac608

Contents?: true

Size: 1.68 KB

Versions: 11

Compression:

Stored size: 1.68 KB

Contents

require "vmc/cli/domain/base"

module VMC::Domain
  class Unmap < Base
    desc "Unmap a domain from an organization or space"
    group :domains, :hidden => true
    input :domain, :desc => "Domain to unmap", :argument => :required,
          :from_given => by_name("domain")
    input :organization, :desc => "Organization to unmap the domain from",
          :aliases => %w{--org -o},
          :default => proc { client.current_organization },
          :from_given => by_name(:organization)
    input :space, :desc => "Space to unmap the domain from",
          :default => proc { client.current_space },
          :from_given => by_name(:space)
    input :delete, :desc => "Delete domain", :type => :boolean
    input :really, :type => :boolean, :forget => true, :hidden => true,
          :default => proc { force? || interact }
    def unmap_domain
      domain = input[:domain]

      given_org = input.has?(:organization)
      given_space = input.has?(:space)

      org = input[:organization]
      space = input[:space]

      if input[:delete]
        return unless input[:really, domain.name, :name]

        with_progress("Deleting domain #{c(domain.name, :name)}") do
          domain.delete!
        end

        return
      end

      given_space = true unless given_org || given_space

      remove_domain(domain, space) if given_space
      remove_domain(domain, org) if given_org
    end

    private

    def remove_domain(domain, target)
      with_progress("Unmapping #{c(domain.name, :name)} from #{c(target.name, :name)}") do
        target.remove_domain(domain)
      end
    end

    def ask_really(name, color)
      ask("Really delete #{c(name, color)}?", :default => false)
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
af-0.5.0.beta.11 lib/vmc/cli/domain/unmap.rb
af-0.5.0.beta.10 lib/vmc/cli/domain/unmap.rb
af-0.5.0.beta.9 lib/vmc/cli/domain/unmap.rb
af-0.5.0.beta.8 lib/vmc/cli/domain/unmap.rb
af-0.5.0.beta.7 lib/vmc/cli/domain/unmap.rb
af-0.5.0.beta.6 lib/vmc/cli/domain/unmap.rb
af-0.5.0.beta.5 lib/vmc/cli/domain/unmap.rb
af-0.5.0.beta.4 lib/vmc/cli/domain/unmap.rb
af-0.5.0.beta.3 lib/vmc/cli/domain/unmap.rb
af-0.5.0.beta.2 lib/vmc/cli/domain/unmap.rb
af-0.5.0.beta.1 lib/vmc/cli/domain/unmap.rb