module Argonaut

Constants

VERSION

Public Class Methods

exec(options) click to toggle source
# File lib/argonaut.rb, line 9
def self.exec(options)
  puts "Executing argonaut command with options:\n#{options}" if options.verbose
  gateway = Argonaut::Gateway.new(api_token: nil, url_root: nil)
  interface = Argonaut::Cli.new(gateway: gateway)

  @options = options

  case options.action
  when 'find_app'
    puts interface.find_app(options.application)
  when 'release'
    env, app = parse_env_app(options.env_app)
    puts interface.release!(env, app)
  when 'reserve'
    env, app = parse_env_app(options.env_app)
    puts interface.reserve!(env, app)
  when 'show_teams'
    all_teams = interface.teams
    print_teams(all_teams)
  when 'show_status'
    status = interface.reservations(options.team)
    print_status(status)
  when 'clear_reservations'
    puts interface.clear_reservations
  when 'list_reservations'
    data = interface.list_reservations.fetch('data', nil)
    print_reservations_list(data)
  when 'init_configuration'
    if interface.initialize_configuration_file
      puts "'#{SETTINGS_FILE}' initialized. Modify to update your api token"
    else
      puts "'#{SETTINGS_FILE}' already exists. No initialization needed"
    end
  end
end

Private Class Methods

color(index) click to toggle source
# File lib/argonaut.rb, line 141
def self.color(index)
  colors[index % colors.length]
end
colorize_row(row, index) click to toggle source
# File lib/argonaut.rb, line 145
def self.colorize_row(row, index)
  color = color(index)
  row.map{|cell| "\x1b[38;5;#{color}m#{cell}\e[0m"}
end
colors() click to toggle source
# File lib/argonaut.rb, line 132
def self.colors
  @colors ||= if @options.high_contrast_colors
    # high contrast colors are based on solarized: http://ethanschoonover.com/solarized
    [136, 166, 160, 125, 61, 33, 37, 64]
  else
    [122, 141, 153, 163, 172, 178, 183, 186, 223]
  end
end
find_reservations_for_app(reservations, a) click to toggle source
# File lib/argonaut.rb, line 150
def self.find_reservations_for_app(reservations, a)
  reservations.select{|r| r['application']['id'] == a['id']}
end
format_date_time(json_time) click to toggle source
# File lib/argonaut.rb, line 49
def self.format_date_time(json_time)
  Time.parse(json_time).getlocal.strftime(@options.time_format || '%d %b %Y %l:%M %p')
end
parse_env_app(env_app) click to toggle source
# File lib/argonaut.rb, line 154
def self.parse_env_app(env_app)
  env_app.split(':')
end
print_reservations_list(data) click to toggle source
print_status(status_hash) click to toggle source
print_teams(teams_hash) click to toggle source