Class: Superbot::Cloud::CLI::Schedule::ListCommand

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

Constant Summary collapse

OUTPUT_HEADERS =
{
  id: { name: "ID", column_size: 10 },
  test_name: { name: "Test", column_size: 25 },
  starts_at: { name: "Scheduled Time", column_size: 20 },
  region: { name: "Region", column_size: 20 },
  status: { name: "Status", column_size: 15 },
  parallel: { name: "Bots", column_size: 10 },
  base_url: { name: "Base URL", column_size: 20 }
}.freeze

Instance Method Summary collapse

Methods inherited from LoginRequiredCommand

#run, run

Methods included from Validations

#require_login

Instance Method Details

#executeObject



21
22
23
# File 'lib/superbot/cloud/cli/schedule/list_command.rb', line 21

def execute
  list_schedules
end

#list_schedulesObject



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

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

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

  if quiet?
    puts(api_response[:schedules].map { |schedule| schedule[:id] })
  else
    puts "Organization: #{api_response[:organization]}"
    puts "Schedules:"
    puts OUTPUT_HEADERS.values.map { |header| header[:name].ljust(header[:column_size]) }.join
    api_response[:schedules].each do |schedule|
      row = schedule.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