Sha256: 228b9fc6c999d3163254b01161007ba1d4c4f4e952da2c899ad664502e9a6129

Contents?: true

Size: 1.51 KB

Versions: 4

Compression:

Stored size: 1.51 KB

Contents

require 'yaml'
require_relative 'common'

module Kontena::Cli::Apps
  class ListCommand < Clamp::Command
    include Kontena::Cli::Common
    include Common

    option ['-f', '--file'], 'FILE', 'Specify an alternate Kontena compose file', attribute_name: :filename, default: 'kontena.yml'
    option ['-p', '--project-name'], 'NAME', 'Specify an alternate project name (default: directory name)'

    parameter "[SERVICE] ...", "Services to start"

    attr_reader :services, :service_prefix

    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

    def show_services(services)
      puts "%-30.30s %-50.50s %-15s %-10.10s %-15.20s %-50s" % ['NAME', 'IMAGE', 'INSTANCES', 'STATEFUL', 'STATE', 'PORTS']

      services.each do |service_name, opts|
        service = get_service(token, prefixed_name(service_name)) rescue false
        if service
          state = service['stateful'] ? 'yes' : 'no'

          ports = service['ports'].map{|p| "#{p['ip']}:#{p['node_port']}->#{p['container_port']}/#{p['protocol']}"}.join(", ")
          puts "%-30.30s %-50.50s %-15.10s %-10.10s %-15.20s %-50s" % [service['name'], service['image'], service['container_count'], state, service['state'], ports]
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
kontena-cli-0.9.3 lib/kontena/cli/apps/list_command.rb
kontena-cli-0.9.2 lib/kontena/cli/apps/list_command.rb
kontena-cli-0.9.1 lib/kontena/cli/apps/list_command.rb
kontena-cli-0.9.0 lib/kontena/cli/apps/list_command.rb