Sha256: a4564fceab2596acfa87db227453d058a7d99fa0626255cdb35dfbd1e8829950

Contents?: true

Size: 822 Bytes

Versions: 14

Compression:

Stored size: 822 Bytes

Contents

module Kontena::Cli::Plugins
  class SearchCommand < Clamp::Command

    parameter '[NAME]', 'Search text'

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

    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
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
kontena-cli-0.15.5 lib/kontena/cli/plugins/search_command.rb
kontena-cli-0.15.5.rc2 lib/kontena/cli/plugins/search_command.rb
kontena-cli-0.15.5.rc1 lib/kontena/cli/plugins/search_command.rb
kontena-cli-0.15.4 lib/kontena/cli/plugins/search_command.rb
kontena-cli-0.15.4.rc2 lib/kontena/cli/plugins/search_command.rb
kontena-cli-0.15.4.rc1 lib/kontena/cli/plugins/search_command.rb
kontena-cli-0.15.4.pre1 lib/kontena/cli/plugins/search_command.rb
kontena-cli-0.15.3 lib/kontena/cli/plugins/search_command.rb
kontena-cli-0.15.2 lib/kontena/cli/plugins/search_command.rb
kontena-cli-0.15.1 lib/kontena/cli/plugins/search_command.rb
kontena-cli-0.15.0 lib/kontena/cli/plugins/search_command.rb
kontena-cli-0.15.0.rc3 lib/kontena/cli/plugins/search_command.rb
kontena-cli-0.15.0.rc2 lib/kontena/cli/plugins/search_command.rb
kontena-cli-0.15.0.rc1 lib/kontena/cli/plugins/search_command.rb