Class: KubeWrapper::Runner
- Inherits:
-
Object
- Object
- KubeWrapper::Runner
- Includes:
- Colors
- Defined in:
- lib/kube_wrapper/runner.rb
Overview
Runner creates a REPL to run kubectl commands
Constant Summary collapse
- COMMANDS =
{ help: { cmds: ['?', '-h', '--help'], blurb: 'Prints this help blurb' }, set_namespace: { cmds: ['set-n', '-n'], blurb: " Changes namespace prefix for further commands to $1. \\\n Pass nothing to print all available namespaces\n DESC\n },\n clear: {\n cmds: %w[cl clear],\n blurb: 'Clears the screen'\n },\n set_context: {\n cmds: ['set-c', '-c'],\n blurb: <<~DESC\n Changes kubernetes context. \\\n Pass nothing to print all available contexts\n DESC\n }\n}.freeze\n"
Constants included from Colors
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
Instance Method Summary collapse
-
#initialize(io_in = STDIN, io_out = STDOUT) ⇒ Runner
constructor
A new instance of Runner.
- #on(key, &block) ⇒ Object
- #start! ⇒ Object
Methods included from Colors
#print_cyan, #print_red, #print_yellow
Constructor Details
#initialize(io_in = STDIN, io_out = STDOUT) ⇒ Runner
Returns a new instance of Runner.
38 39 40 41 42 43 44 |
# File 'lib/kube_wrapper/runner.rb', line 38 def initialize(io_in = STDIN, io_out = STDOUT) @io_in = io_in @io_out = io_out @namespace = 'default' @context = `kubectl config current-context`.chomp @callbacks = {} end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
36 37 38 |
# File 'lib/kube_wrapper/runner.rb', line 36 def context @context end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
36 37 38 |
# File 'lib/kube_wrapper/runner.rb', line 36 def namespace @namespace end |
Instance Method Details
#on(key, &block) ⇒ Object
46 47 48 |
# File 'lib/kube_wrapper/runner.rb', line 46 def on(key, &block) @callbacks[key] = block end |
#start! ⇒ Object
50 51 52 53 54 |
# File 'lib/kube_wrapper/runner.rb', line 50 def start! @callbacks[:start]&.call print_help loop { run } end |