Sha256: ac04956a8c017d8623bb8f1cbf19aa084ad0adb4c6f9f4b9ab3d47f3e246175c

Contents?: true

Size: 1.7 KB

Versions: 3

Compression:

Stored size: 1.7 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'

              ThreeScaleToolbox::CLI.output_flag(self)
              param       :remote
              param       :service_ref

              runner ListSubcommand
            end
          end

          def run
            printer.print_collection service_methods
          end

          private

          def service_methods
            @service_methods ||= service.methods service_hits_id
          end

          def service_hits_id
            @service_hits_id ||= service.hits.fetch('id')
          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

          def printer
            # keep backwards compatibility
            options.fetch(:output, CLI::CustomTablePrinter.new(FIELDS_TO_SHOW))
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
3scale_toolbox-0.17.1 lib/3scale_toolbox/commands/methods_command/list_command.rb
3scale_toolbox-0.17.0 lib/3scale_toolbox/commands/methods_command/list_command.rb
3scale_toolbox-0.16.0 lib/3scale_toolbox/commands/methods_command/list_command.rb