Module: Argonaut
- Defined in:
- lib/argonaut.rb,
lib/argonaut/cli.rb,
lib/argonaut/gateway.rb,
lib/argonaut/version.rb,
lib/argonaut/settings.rb,
lib/argonaut/constants.rb
Defined Under Namespace
Classes: Cli, Constants, Gateway, Settings
Constant Summary collapse
- VERSION =
"0.1.10"
Class Method Summary collapse
- .color(index) ⇒ Object
- .colorize_row(row, index) ⇒ Object
- .colors ⇒ Object
- .exec(options) ⇒ Object
- .find_reservations_for_app(reservations, a) ⇒ Object
- .format_date_time(json_time) ⇒ Object
- .parse_env_app(env_app) ⇒ Object
- .print_reservations_list(data) ⇒ Object
- .print_status(status_hash) ⇒ Object
- .print_teams(teams_hash) ⇒ Object
Class Method Details
.color(index) ⇒ Object
141 142 143 |
# File 'lib/argonaut.rb', line 141 def self.color(index) colors[index % colors.length] end |
.colorize_row(row, index) ⇒ Object
145 146 147 148 |
# 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 ⇒ Object
132 133 134 135 136 137 138 139 |
# 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 |
.exec(options) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/argonaut.rb', line 9 def self.exec() puts "Executing argonaut command with options:\n#{}" if .verbose gateway = Argonaut::Gateway.new(api_token: nil, url_root: nil) interface = Argonaut::Cli.new(gateway: gateway) @options = case .action when 'find_app' puts interface.find_app(.application) when 'release' env, app = parse_env_app(.env_app) puts interface.release!(env, app) when 'reserve' env, app = parse_env_app(.env_app) puts interface.reserve!(env, app) when 'show_teams' all_teams = interface.teams print_teams(all_teams) when 'show_status' status = interface.reservations(.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 |
.find_reservations_for_app(reservations, a) ⇒ Object
150 151 152 |
# 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) ⇒ Object
49 50 51 |
# 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) ⇒ Object
154 155 156 |
# File 'lib/argonaut.rb', line 154 def self.parse_env_app(env_app) env_app.split(':') end |
.print_reservations_list(data) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/argonaut.rb', line 66 def self.print_reservations_list(data) if data.empty? puts 'You have not reserved any environments for testing 😏' return end rows = [] rows << [ 'Environment', 'Application', 'Reserved At' ] table = Terminal::Table.new :rows => rows table << :separator data.each do |r| table.add_row [ r['environment'], r['application'], format_date_time(r['reserved_at']) ] end puts table end |
.print_status(status_hash) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/argonaut.rb', line 84 def self.print_status(status_hash) unless status_hash puts 'Nothing was found here 😟' return end applications = status_hash.fetch('applications', []) environments = status_hash.fetch('environments', []) reservations = status_hash.fetch('reservations', []) header = [' '] + environments.map {|e| e['name'] } rows = [] rows << header table = Terminal::Table.new :rows => rows table << :separator empty_cells = (1..environments.size).map{|_| " "} sentinel = 0 applications.each do |a| cells = empty_cells.dup reservations_for_app = find_reservations_for_app(reservations, a) if reservations_for_app.empty? table.add_row([ a['name'] ] + empty_cells) else reservations_for_app.each do |r| idx = environments.find_index{|e| e['id'] == r['environment']['id'] } cells[idx] = r['user']['username'] end row = if @options.colorize_rows colorize_row([ a['name'] ] + cells, sentinel) else [ a['name'] ] + cells end table.add_row(row) sentinel += 1 end end puts table end |
.print_teams(teams_hash) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/argonaut.rb', line 53 def self.print_teams(teams_hash) rows = [] rows << ['Id', 'Name', 'Description'] table = Terminal::Table.new :rows => rows table << :separator teams_hash.each do |t| table.add_row [ t['id'], t['name'], t['description'] ] end puts table end |