class Kontena::Cli::Containers::ListCommand

Constants

NON_STOP_STATES

Public Instance Methods

container_id(row) click to toggle source
# File lib/kontena/cli/containers/list_command.rb, line 33
def container_id(row)
  if row['node']
    "#{row['node']['name']}/#{row['name']}"
  else
    "/#{row['name']}"
  end
end
container_state(row) click to toggle source
# File lib/kontena/cli/containers/list_command.rb, line 47
def container_state(row)
  NON_STOP_STATES.find { |state| row.fetch('state', {})[state] == true } || pastel.cyan('stopped')
end
execute() click to toggle source
# File lib/kontena/cli/containers/list_command.rb, line 20
def execute
  result = spin_if(!quiet?, "Retrieving container list") do
    Array(client.get("containers/#{current_grid}#{'?all=1' if all?}")['containers'])
  end

  print_table(result.reverse) do |row|
    row['id'] = container_id(row)
    row['created_at'] = time_ago(row['created_at'])
    row['cmd'] = truncate_cmd(row)
    row['state'] = container_state(row)
  end
end
fields() click to toggle source
# File lib/kontena/cli/containers/list_command.rb, line 15
def fields
  return ['id'] if quiet?
  { container_id: 'id', image: 'image', command: 'cmd', created: 'created_at', status: 'state' }
end
truncate_cmd(row) click to toggle source
# File lib/kontena/cli/containers/list_command.rb, line 41
def truncate_cmd(row)
  cmd = row['cmd'].nil? ? '' : row['cmd'].join(' ')
  cmd = "#{cmd[0..24]}#{pastel.cyan('..')}" if cmd.length > 26
  "\"#{cmd}\""
end