civo_cli 0.3.14 → 0.3.15

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8f2eab61a5327829f94ecaf9a6f7ebb9ee6ec5e9a1cd72794f2a457c548bd589
4
- data.tar.gz: 639b6f698fa9eb70af008a1ef107cb55ab647c8d58773f4156bab231177e202b
3
+ metadata.gz: 2aabcc396a2225eb28d5f2f79c73478007b634bb6de5d69f43db7c6f40318f84
4
+ data.tar.gz: 7098b73a6754c32efdd137416bebf318867843875cbb5a2c31ba980d37b20488
5
5
  SHA512:
6
- metadata.gz: a204b476dac69c523fd47381166ff80ef7a831cd5a001a7b9dabb5e6e48b43ba5f78e75a84a5572d69b7981582696da698d493a89027baec16547a0d0f19559d
7
- data.tar.gz: d05142457ecf03e974733346601ea04165e6e6d8228458a971c223a6e3a9a49bdd16feb5b4e47e69082e99a6947e75197be16dff6aab9837a917332a97b4c138
6
+ metadata.gz: 24d185d2934e3138ae7c0bd4eb50b5c5580f684216bf9c4cb03d7cfc016713e0a3a14314643c97c16b52d9307af4dc4831d0550eb842d9b04ee8a7adca437ded
7
+ data.tar.gz: 6a1d5caa05c0792fcc768aadef6c36984aea1faeaacf84748d3e1df4498995162dab7aa8a55049d0e0b60a10246f40610baaa835ad9fc586999ebe5d389dceea
data/CHANGELOG.md CHANGED
@@ -3,6 +3,10 @@ All notable changes to the Civo CLI will be documented in this file.
3
3
 
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
5
5
 
6
+ ## [0.3.15] - 2019-08-30
7
+ ### Add
8
+ - Added plan support to the Kubernetes marketplace
9
+
6
10
  ## [0.3.14] - 2019-08-28
7
11
  ### Fixed
8
12
  - Removed debug level logging for Kubernetes marketplace applications commands
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- civo_cli (0.3.14)
4
+ civo_cli (0.3.15)
5
5
  bundler (~> 1.17)
6
6
  civo (>= 1.2.8)
7
7
  colorize
@@ -0,0 +1,22 @@
1
+ class AskService
2
+ def self.available?
3
+ STDIN.tty?
4
+ end
5
+
6
+ def self.choose(label, options)
7
+ result = options.first
8
+ printf "#{label} (#{options.join(", ")}) [#{options.first}]: "
9
+ input = STDIN.gets.chomp
10
+ result = input unless input.empty?
11
+ unless options.include?(result)
12
+ puts "That wasn't one of the available options.".colorize(:red) + " Please try again."
13
+ result = choose(label, options)
14
+ end
15
+ result
16
+ end
17
+ end
18
+
19
+ trap "SIGINT" do
20
+ puts "Exiting..."
21
+ exit 2
22
+ end
@@ -1,3 +1,3 @@
1
1
  module CivoCLI
2
- VERSION = "0.3.14"
2
+ VERSION = "0.3.15"
3
3
  end
data/lib/finder.rb CHANGED
@@ -20,7 +20,7 @@ class Finder
20
20
  def self.detect_app(name)
21
21
  result = []
22
22
  Civo::Kubernetes.applications.items.each do |app|
23
- result << app if app.name.downcase.include?(name)
23
+ result << app if app.name.downcase.include?(name.downcase)
24
24
  end
25
25
 
26
26
  if result.count.zero?
data/lib/kubernetes.rb CHANGED
@@ -55,7 +55,12 @@ module CivoCLI
55
55
  puts "Installed marketplace applications:"
56
56
  rows = []
57
57
  cluster.installed_applications.each do |application|
58
- rows << [application.application, application.version, application.installed, application.category]
58
+ name = application.application
59
+ if application.plan
60
+ name += " #{application.plan}"
61
+ end
62
+ installed = application.installed ? "Yes" : "Not yet"
63
+ rows << [name, application.version, installed, application.category]
59
64
  end
60
65
  puts Terminal::Table.new headings: ['Name', 'Version', 'Installed', 'Category'], rows: rows
61
66
  end
@@ -94,6 +99,7 @@ module CivoCLI
94
99
  option :wait, type: :boolean, banner: 'wait until cluster is running'
95
100
  option :save, type: :boolean
96
101
  option :switch, type: :boolean
102
+ option :applications, type: :string
97
103
  long_desc <<-LONGDESC
98
104
  Create a new Kubernetes cluster with name (randomly assigned if blank), instance size (default: g2.medium),
99
105
  \x5\x5Optional parameters are as follows:
@@ -106,7 +112,33 @@ module CivoCLI
106
112
  LONGDESC
107
113
  def create(name = CivoCLI::NameGenerator.create, *args)
108
114
  CivoCLI::Config.set_api_auth
109
- @cluster = Civo::Kubernetes.create(name: name, target_nodes_size: options[:size], num_target_nodes: options[:nodes], applications: options[:applications])
115
+
116
+ applications = []
117
+ options[:applications].split(",").map(&:chomp).each do |name|
118
+ name, plan = name.split(":")
119
+ app = Finder.detect_app(name)
120
+ plans = app.plans&.items
121
+
122
+ if app && plans.present? && plan.blank?
123
+ if AskService.available?
124
+ plan = AskService.choose("You requested to add #{app.name} but didn't select a plan. Please choose one...", plans.map(&:label))
125
+ if plan.present?
126
+ puts "Thank you, next time you could use \"#{app.name}:#{plan}\" to choose automatically"
127
+ end
128
+ else
129
+ puts "You need to specify a plan".colorize(:red) + " from those available (#{plans.join(", ")} using the syntax \"#{app.name}:plan\""
130
+ exit 1
131
+ end
132
+ end
133
+
134
+ if plan.present?
135
+ applications << "#{app.name}:#{plan}"
136
+ else
137
+ applications << app.name
138
+ end
139
+ end
140
+
141
+ @cluster = Civo::Kubernetes.create(name: name, target_nodes_size: options[:size], num_target_nodes: options[:nodes], applications: applications.join(","))
110
142
 
111
143
  if options[:wait]
112
144
  timer = CivoCLI::Timer.new
@@ -13,9 +13,16 @@ module CivoCLI
13
13
  else
14
14
  rows = []
15
15
  Civo::Kubernetes.applications.items.each do |app|
16
- rows << [app.name, app.version, app.category]
16
+ plans = app.plans&.items
17
+ if plans.present?
18
+ plans = plans.map {|p| p.label}.join(", ")
19
+ else
20
+ plans = "Not applicable"
21
+ end
22
+
23
+ rows << [app.name, app.version, app.category, plans]
17
24
  end
18
- puts Terminal::Table.new headings: ['Name', 'Version', 'Category'], rows: rows
25
+ puts Terminal::Table.new headings: ['Name', 'Version', 'Category', 'Plans'], rows: rows
19
26
  end
20
27
  rescue Flexirest::HTTPForbiddenClientException
21
28
  reject_user_access
@@ -49,10 +56,28 @@ module CivoCLI
49
56
  LONGDESC
50
57
  def add(name)
51
58
  CivoCLI::Config.set_api_auth
59
+ name, plan = name.split(":")
52
60
  app = Finder.detect_app(name)
53
61
  cluster = Finder.detect_cluster(options[:cluster])
62
+ plans = app.plans&.items
63
+
64
+ if app && plans.present? && plan.blank?
65
+ if AskService.available?
66
+ plan = AskService.choose("You requested to add #{app.name} but didn't select a plan. Please choose one...", plans.map(&:label))
67
+ if plan.present?
68
+ puts "Thank you, next time you could use \"#{app.name}:#{plan}\" to choose automatically"
69
+ end
70
+ else
71
+ puts "You need to specify a plan".colorize(:red) + " from those available (#{plans.join(", ")} using the syntax \"#{app.name}:plan\""
72
+ exit 1
73
+ end
74
+ end
54
75
 
55
- Civo::Kubernetes.update(id: cluster.id, applications: app.name)
76
+ if plan.present?
77
+ Civo::Kubernetes.update(id: cluster.id, applications: "#{app.name}:#{plan}")
78
+ else
79
+ Civo::Kubernetes.update(id: cluster.id, applications: app.name)
80
+ end
56
81
  puts "Added #{app.name.colorize(:green)} #{app.version} to Kubernetes cluster #{cluster.name.colorize(:green)}"
57
82
  rescue Flexirest::HTTPException => e
58
83
  puts e.result.reason.colorize(:red)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: civo_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.14
4
+ version: 0.3.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Jeffries
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2019-08-28 00:00:00.000000000 Z
13
+ date: 2019-08-30 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake
@@ -205,6 +205,7 @@ files:
205
205
  - civo_cli.gemspec
206
206
  - exe/civo
207
207
  - lib/apikey.rb
208
+ - lib/ask_service.rb
208
209
  - lib/blueprint.rb
209
210
  - lib/civo_cli.rb
210
211
  - lib/civo_cli/version.rb