Sha256: 4a746c023848ad08c4ea2d7679da75dc6ba59bfcb68a5f2f4a2bc886634daade

Contents?: true

Size: 1.69 KB

Versions: 7

Compression:

Stored size: 1.69 KB

Contents

module ThreeScaleToolbox
  module Commands
    module ServiceCommand
      module Show
        class ShowSubcommand < Cri::CommandRunner
          include ThreeScaleToolbox::Command

          def self.command
            Cri::Command.define do
              name        'show'
              usage       'show <remote> <service-id_or_system-name>'
              summary     'Show the information of a service'
              description "Show the information of a service"
              runner ShowSubcommand

              param   :remote
              param   :service_id_or_system_name
            end
          end

          def run
            print_header
            print_data
          end

          private

          SERVICE_FIELDS_TO_SHOW = %w[
            id name state system_name end_user_registration_required
            backend_version deployment_option support_email description
            created_at updated_at
          ]

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

          def ref
            @ref ||= arguments[:service_id_or_system_name]
          end

          def service
            @service ||= find_service
          end

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

          def print_header
            puts SERVICE_FIELDS_TO_SHOW.map { |e| e.upcase }.join("\t")
          end

          def print_data
            puts SERVICE_FIELDS_TO_SHOW.map { |field| service.attrs.fetch(field, '(empty)') }.join("\t")
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
3scale_toolbox-0.15.0 lib/3scale_toolbox/commands/service_command/show_command.rb
3scale_toolbox-0.14.0 lib/3scale_toolbox/commands/service_command/show_command.rb
3scale_toolbox-0.13.0 lib/3scale_toolbox/commands/service_command/show_command.rb
3scale_toolbox-0.12.4 lib/3scale_toolbox/commands/service_command/show_command.rb
3scale_toolbox-0.12.3 lib/3scale_toolbox/commands/service_command/show_command.rb
3scale_toolbox-0.12.2 lib/3scale_toolbox/commands/service_command/show_command.rb
3scale_toolbox-0.11.0 lib/3scale_toolbox/commands/service_command/show_command.rb