Class: Kontena::Cli::Plugins::SearchCommand

Inherits:
Kontena::Command show all
Includes:
Common
Defined in:
lib/kontena/cli/plugins/search_command.rb

Instance Attribute Summary

Attributes inherited from Kontena::Command

#arguments, #exit_code, #result

Instance Method Summary collapse

Methods included from Common

#short_name

Methods inherited from Kontena::Command

banner, callback_matcher, #help_requested?, inherited, requires_current_account_token, requires_current_account_token?, requires_current_grid, requires_current_grid?, requires_current_master, requires_current_master?, requires_current_master_token, requires_current_master_token?, #run, #run_callbacks, #verify_current_account_token, #verify_current_grid, #verify_current_master, #verify_current_master_token

Instance Method Details

#executeObject



9
10
11
12
13
14
15
16
# File 'lib/kontena/cli/plugins/search_command.rb', line 9

def execute
  results = fetch_plugins(name)
  exit_with_error("Cannot access plugin server") unless results
  puts "%-50s %-10s %-60s" % ['NAME', 'VERSION', 'DESCRIPTION']
  results.each do |item|
    puts "%-50s %-10s %-60s" % [short_name(item['name']), item['version'], item['info']]
  end
end

#fetch_plugins(name) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/kontena/cli/plugins/search_command.rb', line 18

def fetch_plugins(name)
  client = Excon.new('https://rubygems.org')
  response = client.get(
    path: "/api/v1/search.json?query=kontena-plugin-#{name}",
    headers: {
      'Content-Type' => 'application/json',
      'Accept' => 'application/json'
    }
  )

  JSON.parse(response.body) rescue nil
end