Class: Central::Cli::Stacks::ListCommand

Inherits:
Clamp::Command
  • Object
show all
Includes:
Common, Common
Defined in:
lib/central/cli/stacks/list_command.rb

Instance Method Summary collapse

Methods included from Common

#calculate_filesystem_stats, #calculate_loads, #calculate_mem_used, #find_stack_by_name, #print_stack, #stacks, #to_gigabytes

Methods included from Common

#access_token=, #add_master, #api_url, #api_url=, #clear_current_stack, #client, #current_master, #current_master=, #current_master_index, #current_stack, #current_stack=, #ensure_custom_ssl_ca, #require_api_url, #require_current_stack, #require_token, #reset_client, #save_settings, #settings, #settings_filename

Instance Method Details

#executeObject



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
# File 'lib/central/cli/stacks/list_command.rb', line 9

def execute
  require_api_url

  if stacks['stacks'].size == 0
    puts "You don't have any stacks yet. Create first one with 'cm stack create' command".colorize(:yellow)
  end

  header = %w(Name Nodes Services Users)
  rows = []

  stacks['stacks'].each do |stack|
    name = if stack['id'] == current_stack
             "#{stack['name']} *"
           else
             stack['name']
           end
    rows << [name, stack['node_count'], stack['service_count'], stack['user_count']]
  end

  ttable = TTY::Table.new header: header, rows: Array.new(rows)
  renderer = TTY::Table::Renderer::Unicode.new(ttable)
  renderer.border.style = :cyan
  renderer.padding = [0, 1, 0, 1]
  puts renderer.render
end