Class: Superbot::Cloud::CLI::Run::ListCommand

Inherits:
BaseCommand show all
Defined in:
lib/superbot/cloud/cli/run/list_command.rb

Constant Summary collapse

OUTPUT_HEADERS =
{
  id: { name: "ID", column_size: 10 },
  test_name: { name: "Test", column_size: 25 },
  region: { name: "Region", column_size: 20 },
  status: { name: "Status", column_size: 10 },
  parallel: { name: "Bots", column_size: 10 },
  loop: { name: "Loop count", column_size: 10 }
}.freeze

Instance Method Summary collapse

Methods inherited from LoginRequiredCommand

#run, run

Methods included from Validations

#require_login

Instance Method Details

#executeObject



20
21
22
# File 'lib/superbot/cloud/cli/run/list_command.rb', line 20

def execute
  list_interactive_runs
end

#list_interactive_runsObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/superbot/cloud/cli/run/list_command.rb', line 24

def list_interactive_runs
  states = all? ? nil : %w[initial running]
  api_response = Superbot::Cloud::Api.request(:interactive_run_list, params: { organization_name: organization, 'aasm_state[]': states })

  abort api_response[:error] if api_response[:error]
  abort "No active interactive runs found for organization #{api_response[:organization]}" if api_response[:interactive_runs].empty?

  if quiet?
    puts(api_response[:interactive_runs].map { |interactive_run| interactive_run[:id] })
  else
    puts "Organization: #{api_response[:organization]}"
    puts "Interactive runs:"
    puts OUTPUT_HEADERS.values.map { |header| header[:name].ljust(header[:column_size]) }.join
    api_response[:interactive_runs].each do |interactive_run|
      row = interactive_run.slice(*OUTPUT_HEADERS.keys).map do |key, value|
        value.to_s.ljust(OUTPUT_HEADERS.dig(key, :column_size))
      end.join
      puts row
    end
  end
end