Sha256: f44ecf971e0c02b98202a4bd53168b00fe9a1f7b01fffe22056718791d403f69

Contents?: true

Size: 1.81 KB

Versions: 13

Compression:

Stored size: 1.81 KB

Contents

require "cf/cli/space/base"

module CF::Space
  class Create < Base
    desc "Create a space in an organization"
    group :spaces
    input :name, :desc => "Space name", :argument => :optional
    input :organization, :desc => "Parent organization",
          :argument => :optional, :aliases => ["--org", "-o"],
          :from_given => by_name(:organization),
          :default => proc { client.current_organization }
    input :target, :desc => "Switch to the space after creation",
          :alias => "-t", :default => false
    input :manager, :desc => "Add yourself as manager", :default => true
    input :developer, :desc => "Add yourself as developer", :default => true
    input :auditor, :desc => "Add yourself as auditor", :default => false

    def create_space
      # TODO: ask org instead
      return invoke :help,
        :command => "create-space" if input[:organization].nil?

      space = client.space
      space.organization = input[:organization]
      space.name = input[:name]

      with_progress("Creating space #{c(space.name, :name)}") do
        space.create!
      end

      if input[:manager]
        with_progress("Adding you as a manager") do
          space.add_manager client.current_user
        end
      end

      if input[:developer]
        with_progress("Adding you as a developer") do
          space.add_developer client.current_user
        end
      end

      if input[:auditor]
        with_progress("Adding you as an auditor") do
          space.add_auditor client.current_user
        end
      end

      if input[:target]
        invoke :target, :organization => space.organization,
          :space => space
      else
        line c("Space created! Use #{b("switch-space #{space.name}")} to target it.", :good)
      end
    end

    private

    def ask_name
      ask("Name")
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
cf-0.6.1.rc4 lib/cf/cli/space/create.rb
cf-0.6.1.rc3 lib/cf/cli/space/create.rb
cf-0.6.1.rc2 lib/cf/cli/space/create.rb
cf-0.6.1.rc1 lib/cf/cli/space/create.rb
cf-0.6.0 lib/cf/cli/space/create.rb
cf-0.6.0.rc8 lib/cf/cli/space/create.rb
cf-0.6.0.rc7 lib/cf/cli/space/create.rb
cf-0.6.0.rc6 lib/cf/cli/space/create.rb
cf-0.6.0.rc5 lib/cf/cli/space/create.rb
cf-0.6.0.rc4 lib/cf/cli/space/create.rb
cf-0.6.0.rc3 lib/cf/cli/space/create.rb
cf-0.6.0.rc2 lib/cf/cli/space/create.rb
cf-0.6.0.rc1 lib/cf/cli/space/create.rb