Class: Central::Cli::Stacks::EnvCommand

Inherits:
Clamp::Command
  • Object
show all
Includes:
Common, Common
Defined in:
lib/central/cli/stacks/env_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



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/central/cli/stacks/env_command.rb', line 11

def execute
  require_api_url

  name_or_current = name.nil? ? current_stack : name

  if name_or_current.nil?
    abort 'No stack selected. Use: cm stack env <name>, or select a stack with: cm stack use <name>'
  else
    stack = find_stack_by_name(name_or_current)
    abort('Stack not found'.colorize(:red)) unless stack

    prefix = export? ? 'export ' : ''

    server = settings['servers'].find { |s| s['name'] == settings['current_server'] }
    if server
      puts "#{prefix}CENTRAL_URI=#{server['url'].sub('http', 'ws')}"
      puts "#{prefix}CENTRAL_TOKEN=#{server['token']}"
    end
  end
end