class Superbot::Cloud::CLI::Run::ListCommand

Constants

OUTPUT_HEADERS

Public Instance Methods

execute() click to toggle source
# File lib/superbot/cloud/cli/run/list_command.rb, line 20
def execute
  list_interactive_runs
end
list_interactive_runs() click to toggle source
# 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