Sha256: 642e6d215a2a65cec91c4a83b1c6b469e8db0050aa0d309f70a27b5fe0d130d7

Contents?: true

Size: 1.61 KB

Versions: 8

Compression:

Stored size: 1.61 KB

Contents

module ThreeScaleToolbox
  module Commands
    module MethodsCommand
      module List
        class ListSubcommand < Cri::CommandRunner
          include ThreeScaleToolbox::Command

          FIELDS_TO_SHOW = %w[id friendly_name system_name description].freeze

          def self.command
            Cri::Command.define do
              name        'list'
              usage       'list [opts] <remote> <service>'
              summary     'list methods'
              description 'List methods'

              param       :remote
              param       :service_ref

              runner ListSubcommand
            end
          end

          def run
            print_header
            print_data
          end

          private

          def print_header
            puts FIELDS_TO_SHOW.map(&:upcase).join("\t")
          end

          def print_data
            hits = service.hits
            service.methods(hits.fetch('id')).each do |method|
              puts FIELDS_TO_SHOW.map { |field| method.fetch(field, '(empty)') }.join("\t")
            end
          end

          def service
            @service ||= find_service
          end

          def find_service
            Entities::Service.find(remote: remote,
                                   ref: service_ref).tap do |svc|
              raise ThreeScaleToolbox::Error, "Service #{service_ref} does not exist" if svc.nil?
            end
          end

          def remote
            @remote ||= threescale_client(arguments[:remote])
          end

          def service_ref
            arguments[:service_ref]
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
3scale_toolbox-0.15.0 lib/3scale_toolbox/commands/methods_command/list_command.rb
3scale_toolbox-0.14.0 lib/3scale_toolbox/commands/methods_command/list_command.rb
3scale_toolbox-0.13.0 lib/3scale_toolbox/commands/methods_command/list_command.rb
3scale_toolbox-0.12.4 lib/3scale_toolbox/commands/methods_command/list_command.rb
3scale_toolbox-0.12.3 lib/3scale_toolbox/commands/methods_command/list_command.rb
3scale_toolbox-0.12.2 lib/3scale_toolbox/commands/methods_command/list_command.rb
3scale_toolbox-0.11.0 lib/3scale_toolbox/commands/methods_command/list_command.rb
3scale_toolbox-0.10.0 lib/3scale_toolbox/commands/methods_command/list_command.rb