kube_wrapper 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 334f97cfae1fd7f26b6d3c68e7b865aeda5dba3b3ee095a3fdf65b836f9235d4
4
- data.tar.gz: 6fca950d764ed6baf45047c7098265416e9b89216a23fadede868c66fbf33ad4
3
+ metadata.gz: 3eb2620cf4fb1a2c49a85399f0c9d2d1a5ce42c1fc76994769aee9ee7b1a3aad
4
+ data.tar.gz: 8b4dc4280e51f8fc988f47241f346bdf71fab1785863de3a0bd5778de2aea734
5
5
  SHA512:
6
- metadata.gz: c327bd3f0c79caa20e3f10c72a1aee4c6809039a2b678c25f049a9c250673e61c621fcc4252a2dccba84d7ba7837e0f4af8daee1ab3ddfa4f1baabfa018979e9
7
- data.tar.gz: 94edd9af89ca865ff601beb01a994b3ed3d064a0b6ec7ecdc8e261f9ec045639111a707d42b47d430a8bb633234dfbfb726dacf547905d1b56144767638ba194
6
+ metadata.gz: 6fc3bee2c6c0bf12ed4d02c802b8b8bc3e7cd134c9b4d0dfc79b776d37cde8bdba14c24aa9906c5a601d61237fbf7d5d799a7fe9b30eaccc8f3fedd874a9becf
7
+ data.tar.gz: 153082642f0ffdea6f6195d04b97d0f21c724bad46148981a67bb313bf9f60b4d02a8ab1d8f4f89db5e0748b7a87dfb1046b77e20d02e39fe51465f0f80f04a6
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kube_wrapper (0.1.1)
4
+ kube_wrapper (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -4,8 +4,9 @@ module KubeWrapper
4
4
  # Colors handles printing colored text to output
5
5
  module Colors
6
6
  COLORS = {
7
+ cyan: "\e[36m",
7
8
  red: "\e[31m",
8
- cyan: "\e[36m"
9
+ yellow: "\e[33m"
9
10
  }.freeze
10
11
 
11
12
  def print_cyan(text)
@@ -16,6 +17,12 @@ module KubeWrapper
16
17
  print_color(text, COLORS[:red])
17
18
  end
18
19
 
20
+ def print_yellow(text)
21
+ print_color(text, COLORS[:yellow])
22
+ end
23
+
24
+ private
25
+
19
26
  def print_color(text, color)
20
27
  @io_out.print "#{color}#{text}\e[0m"
21
28
  end
@@ -22,15 +22,22 @@ module KubeWrapper
22
22
  clear: {
23
23
  cmds: %w[cl clear],
24
24
  blurb: 'Clears the screen'
25
+ },
26
+ set_context: {
27
+ cmds: ['set-c', '-c'],
28
+ blurb: <<~DESC
29
+ Changes kubernetes context. Pass nothing to print all available contexts
30
+ DESC
25
31
  }
26
32
  }.freeze
27
33
 
28
- attr_reader :namespace
34
+ attr_reader :context, :namespace
29
35
 
30
36
  def initialize(io_in = STDIN, io_out = STDOUT)
31
37
  @io_in = io_in
32
38
  @io_out = io_out
33
39
  @namespace = 'default'
40
+ @context = `kubectl config current-context`.chomp
34
41
  @callbacks = {}
35
42
  end
36
43
 
@@ -64,23 +71,38 @@ module KubeWrapper
64
71
  exit!
65
72
  end
66
73
 
74
+ def update_context!(context)
75
+ if context.nil? || context.empty?
76
+ puts `kubectl config get-contexts`
77
+ return
78
+ end
79
+
80
+ context = Shellwords.escape(context)
81
+ result = `kubectl config use-context #{context}`
82
+ return if result.empty?
83
+
84
+ @io_out.puts "Context set to #{context}"
85
+ @context = context
86
+ end
87
+
67
88
  def update_namespace!(namespace)
68
89
  @namespace = namespace || 'default'
69
90
  @io_out.puts "Namespace set to #{@namespace}"
70
91
  end
71
92
 
72
- def handle_input(input)
93
+ def handle_input(input) # rubocop:disable Metrics/AbcSize
73
94
  case input.first
74
95
  when *COMMANDS[:help][:cmds] then print_help
75
96
  when *COMMANDS[:set_namespace][:cmds] then update_namespace!(input[1])
76
- when *COMMANDS[:clear][:cmds] then print "\e[2J\e[f"
97
+ when *COMMANDS[:clear][:cmds] then @io_out.print "\e[2J\e[f"
98
+ when *COMMANDS[:set_context][:cmds] then update_context!(input[1])
77
99
  else
78
100
  @io_out.puts `kubectl -n #{namespace} #{Shellwords.shelljoin(input)}`
79
101
  end
80
- nil
81
102
  end
82
103
 
83
104
  def run
105
+ print_yellow "(#{context}) "
84
106
  print_cyan "kubectl -n #{namespace} "
85
107
  input = fetch_input
86
108
  handle_input(input)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KubeWrapper
4
- VERSION = '0.1.1'
4
+ VERSION = '0.2.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kube_wrapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Blues
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-22 00:00:00.000000000 Z
11
+ date: 2020-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler