4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/kontena/plugin/packet/type_option.rb', line 4
def self.included(base)
base.option "--type", "SLUG", "Packet server plan type", attribute_name: :plan
base.class_eval do
def default_plan
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 ||
plans.each do |plan|
.choice plan.name, plan.slug
end
end
end
end
end
end
|