Sha256: 3fec44f64f075ffe46259663e346ff0605426672b56b98529a9351a0038159d7

Contents?: true

Size: 845 Bytes

Versions: 30

Compression:

Stored size: 845 Bytes

Contents

require_relative 'common'

module Kontena::Cli::Plugins
  class SearchCommand < Kontena::Command
    include Common

    parameter '[NAME]', 'Search text'

    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

    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

30 entries across 30 versions & 1 rubygems

Version Path
kontena-cli-1.0.6 lib/kontena/cli/plugins/search_command.rb
kontena-cli-1.0.6.rc1 lib/kontena/cli/plugins/search_command.rb
kontena-cli-1.0.5 lib/kontena/cli/plugins/search_command.rb
kontena-cli-1.0.5.rc1 lib/kontena/cli/plugins/search_command.rb
kontena-cli-1.0.5.pre1 lib/kontena/cli/plugins/search_command.rb
kontena-cli-1.0.4 lib/kontena/cli/plugins/search_command.rb
kontena-cli-1.0.4.rc2 lib/kontena/cli/plugins/search_command.rb
kontena-cli-1.0.4.rc1 lib/kontena/cli/plugins/search_command.rb
kontena-cli-1.0.3 lib/kontena/cli/plugins/search_command.rb
kontena-cli-1.0.3.rc1 lib/kontena/cli/plugins/search_command.rb
kontena-cli-1.0.2 lib/kontena/cli/plugins/search_command.rb
kontena-cli-1.0.2.rc2 lib/kontena/cli/plugins/search_command.rb
kontena-cli-1.0.2.rc1 lib/kontena/cli/plugins/search_command.rb
kontena-cli-1.0.2.pre1 lib/kontena/cli/plugins/search_command.rb
kontena-cli-1.0.1 lib/kontena/cli/plugins/search_command.rb
kontena-cli-1.0.1.rc3 lib/kontena/cli/plugins/search_command.rb
kontena-cli-1.0.1.rc2 lib/kontena/cli/plugins/search_command.rb
kontena-cli-1.0.1.rc1 lib/kontena/cli/plugins/search_command.rb
kontena-cli-1.0.0 lib/kontena/cli/plugins/search_command.rb
kontena-cli-1.0.0.rc2 lib/kontena/cli/plugins/search_command.rb