Sha256: 2e7bfec8aca5c1b9dee9183e56e981f525a527b165c34fef15e53edf50e3ea08

Contents?: true

Size: 1.97 KB

Versions: 4

Compression:

Stored size: 1.97 KB

Contents

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

          FIELDS_TO_SHOW = %w[id name description state enabled account_id service_id plan_id
                              user_key application_id].freeze

          def self.command
            Cri::Command.define do
              name        'show'
              usage       'show [opts] <remote> <application>'
              summary     'show application attributes'
              description <<-HEREDOC
              Show application attributes
              \n Application param allows:
              \n * User_key (API key)
              \n * App_id (from app_id/app_key pair) or Client ID (for OAuth and OpenID Connect authentication modes)
              \n * Application internal id
              HEREDOC

              param       :remote
              param       :application

              runner ShowSubcommand
            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
            puts FIELDS_TO_SHOW.map { |field| app_attrs.fetch(field, '(empty)') }.join("\t")
          end

          def app_attrs
            @app_attrs ||= application.attrs
          end

          def application
            @application ||= find_application
          end

          def find_application
            Entities::Application.find(remote: remote, ref: application_ref).tap do |app|
              raise ThreeScaleToolbox::Error, "Application #{application_ref} does not exist" if app.nil?
            end
          end

          def application_ref
            arguments[:application]
          end

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
3scale_toolbox-0.15.0 lib/3scale_toolbox/commands/application_command/show_command.rb
3scale_toolbox-0.14.0 lib/3scale_toolbox/commands/application_command/show_command.rb
3scale_toolbox-0.13.0 lib/3scale_toolbox/commands/application_command/show_command.rb
3scale_toolbox-0.12.4 lib/3scale_toolbox/commands/application_command/show_command.rb