Class: Mortar::ListCommand

Inherits:
Command
  • Object
show all
Includes:
ClientHelper, TTYHelper
Defined in:
lib/mortar/list_command.rb

Constant Summary

Constants inherited from Command

Command::CHECKSUM_ANNOTATION, Command::LABEL

Instance Method Summary collapse

Methods included from TTYHelper

#pastel

Methods included from ClientHelper

#build_kubeconfig_from_env, #client, #create_client

Instance Method Details

#executeObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/mortar/list_command.rb', line 14

def execute
  shots = Hash.new(0)

  client.list_resources(labelSelector: LABEL).select{ |r|
    r..labels&.dig(LABEL)
  }.uniq{ |r|
    # Kube api returns same object from many api versions...
    "#{r.kind}/#{r..name}/#{r..namespace}"
  }.each do |resource|
    shot_name = resource..labels&.dig(LABEL)
    shots[shot_name] += 1
  end

  if quiet?
    shots.each_key do |k|
      puts k
    end
  else
    table = TTY::Table.new %w(NAME RESOURCES), shots.to_a
    puts table.render(:basic)
  end
end