Sha256: 680e232dd64cc2910be9605feb5fd1318b55d6fd7f746fc7e9bad3e19482cb06

Contents?: true

Size: 1.3 KB

Versions: 1

Compression:

Stored size: 1.3 KB

Contents

module Kontena::Plugin::Packet
  module TypeOption

    def self.included(base)
      base.option "--type", "SLUG", "Packet server plan type", attribute_name: :plan
      base.class_eval do
        def default_project
          require 'packet'

          client = Packet::Client.new(self.token || (self.respond_to?(:default_token) && self.default_token))

          plans = []
          spinner "Retrieving a list of available plans at Packet" do
            plans = client.list_plans
          end

          case plans.size
          when 0
            abort 'You do not have access to any plans on Packet'
          when 1
            unless Kontena.prompt.yes?("You have access to plan '#{plans.first.name}'. Use?")
              abort 'Aborted'
            end
            plans.first.slug
          else
            puts
            puts pastel.bright_blue("Packet plans:")
            puts
            plans.each do |plan|
              puts pastel.green("  #{"%-11s" % "#{plan.name}:"}")
              puts pastel.bright_blue("     #{plan.description}")
            end
            puts

            Kontena.prompt.select "Packet plan:" do |menu|
              plans.each do |plan|
                menu.choice plan.name, plan.slug
              end
            end
          end
        end
      end
    end
  end
end


Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
kontena-plugin-packet-0.2.0 lib/kontena/plugin/packet/type_option.rb