Class: Central::Cli::Apps::ListCommand
- Inherits:
-
Clamp::Command
- Object
- Clamp::Command
- Central::Cli::Apps::ListCommand
- Includes:
- Common, Common, StackOptions
- Defined in:
- lib/central/cli/apps/list_command.rb
Instance Attribute Summary collapse
-
#service_prefix ⇒ Object
readonly
Returns the value of attribute service_prefix.
-
#services ⇒ Object
readonly
Returns the value of attribute services.
Instance Method Summary collapse
Methods included from Common
#app_json, #create_yml, #current_dir, #extend_env_vars, #extend_options, #extend_secrets, #load_services, #normalize_env_vars, #parse_services, #prefixed_name, #require_config_file, #service_exists?, #token, #valid_addons
Methods included from Services::ServicesHelper
#create_service, #delete_service, #deploy_service, #get_service, #int_to_filesize, #parse_image, #parse_links, #parse_log_opts, #parse_memory, #parse_ports, #parse_relative_time, #parse_secrets, #parse_service_id, #restart_service, #scale_service, #show_service, #start_service, #stop_service, #update_service, #wait_for_deploy_to_finish
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
Methods included from StackOptions
Instance Attribute Details
#service_prefix ⇒ Object (readonly)
Returns the value of attribute service_prefix.
15 16 17 |
# File 'lib/central/cli/apps/list_command.rb', line 15 def service_prefix @service_prefix end |
#services ⇒ Object (readonly)
Returns the value of attribute services.
15 16 17 |
# File 'lib/central/cli/apps/list_command.rb', line 15 def services @services end |
Instance Method Details
#execute ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/central/cli/apps/list_command.rb', line 17 def execute require_config_file(filename) @service_prefix = project_name || current_dir @services = load_services(filename, service_list, service_prefix) if services.size > 0 show_services(services) elsif !service_list.empty? puts "No such service: #{service_list.join(', ')}".colorize(:red) end end |
#show_services(services) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/central/cli/apps/list_command.rb', line 29 def show_services(services) header = %w(Name Images Instances Stateful State Ports) rows = [] services.each do |service_name, _opts| service = begin get_service(token, prefixed_name(service_name)) rescue false end if service name = service['name'].sub("#{@service_prefix}-", '') state = service['stateful'] ? 'yes' : 'no' ports = service['ports'].map do|p| "#{p['ip']}:#{p['node_port']}->#{p['container_port']}/#{p['protocol']}" end.join(', ') running = service['instances']['running'] desired = service['container_count'] instances = "#{running} / #{desired}" rows << [ name, service['image'], instances, state, (service['state'] ? ' ✓ '.colorize(:green) : ' ✘ '.colorize(:red)), ports ] else rows << [service_name.colorize(:yellow), '-', '-', '-', '-', '-'] end 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 |