Sha256: 59c62c7a0b3423acc304c020c09dbf997a1bdc993d790363c523ce28ce3a5866

Contents?: true

Size: 1.61 KB

Versions: 10

Compression:

Stored size: 1.61 KB

Contents

require "vmc/cli"

module VMC
  class Organization < CLI
    def precondition
      super
      fail "This command is v2-only." unless v2?
    end

    def self.by_name(what, obj = what)
      proc { |name, *_|
        client.send(:"#{obj}_by_name", name) ||
          fail("Unknown #{what} '#{name}'")
      }
    end

    desc "Show organization information"
    group :organizations
    input(:organization, :aliases => ["--org", "-o"],
          :argument => :optional, :from_given => by_name("organization"),
          :desc => "Organization to show") {
      client.current_organization
    }
    input :full, :type => :boolean,
      :desc => "Show full information for appspaces"
    def org(input)
      org = input[:organization]

      if quiet?
        puts org.name
        return
      end

      line "#{c(org.name, :name)}:"

      indented do
        line "domains: #{name_list(org.domains)}"

        if input[:full]
          line "spaces:"

          spaced(org.spaces(2)) do |s|
            indented do
              invoke :space, :space => s
            end
          end
        else
          line "spaces: #{name_list(org.spaces)}"
        end
      end
    end


    desc "List available organizations"
    group :organizations
    def orgs(input)
      orgs =
        with_progress("Getting organizations") do
          client.organizations
        end

      line unless quiet?

      orgs.each do |o|
        line c(o.name, :name)
      end
    end

    private

    def name_list(xs)
      if xs.empty?
        d("none")
      else
        xs.collect { |x| c(x.name, :name) }.join(", ")
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
vmc-0.4.0.beta.36 vmc-ng/lib/vmc/cli/organization.rb
vmc-0.4.0.beta.35 vmc-ng/lib/vmc/cli/organization.rb
vmc-0.4.0.beta.34 vmc-ng/lib/vmc/cli/organization.rb
vmc-0.4.0.beta.33 vmc-ng/lib/vmc/cli/organization.rb
vmc-0.4.0.beta.32 vmc-ng/lib/vmc/cli/organization.rb
vmc-0.4.0.beta.31 vmc-ng/lib/vmc/cli/organization.rb
vmc-0.4.0.beta.30 vmc-ng/lib/vmc/cli/organization.rb
vmc-0.4.0.beta.29 vmc-ng/lib/vmc/cli/organization.rb
vmc-0.4.0.beta.28 vmc-ng/lib/vmc/cli/organization.rb
vmc-0.4.0.beta.27 vmc-ng/lib/vmc/cli/organization.rb