<commit_before>require_relative 'services_helper'

module Kontena::Cli::Services
  class ListCommand < Clamp::Command
    include Kontena::Cli::Common
    include ServicesHelper

    def execute
      require_api_url
      token = require_token

      grids = client(token).get("grids/#{current_grid}/services")
      puts "%-30.30s %-40.40s %-10s %-8s" % ['NAME', 'IMAGE', 'INSTANCES', 'STATEFUL']
      grids['services'].each do |service|
        state = service['stateful'] ? 'yes' : 'no'
        puts "%-30.30s %-40.40s %-10.10s %-8s" % [service['name'], service['image'], service['container_count'], state]
      end
    end
  end
end<commit_msg>show state in service list<commit_after>require_relative 'services_helper'

module Kontena::Cli::Services
  class ListCommand < Clamp::Command
    include Kontena::Cli::Common
    include ServicesHelper

    def execute
      require_api_url
      token = require_token

      grids = client(token).get("grids/#{current_grid}/services")
      titles = ['NAME', 'IMAGE', 'INSTANCES', 'STATEFUL', 'STATE']
      puts "%-30.30s %-50.50s %-10s %-8s %-10s" % titles
      grids['services'].each do |service|
        stateful = service['stateful'] ? 'yes' : 'no'
        image = service['image']
        if image.length > 50
          image = image[0..10] << '...' << image[-35..-1]
        end
        vars = [
          service['name'],
          image,
          service['container_count'],
          stateful,
          service['state']
        ]
        puts "%-30.30s %-50.50s %-10.10s %-8s %-10s" % vars
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.1560328490208465, 'fraction_numerical': 0.03790271636133923, 'mean_word_length': 2.583710407239819, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6261384', 'n_tokens_mistral': 547, 'n_tokens_neox': 517, 'n_words': 114}