Sha256: 988ac55bbea472edfae2edec47f9168fbaff01b8e46abea97414dacd65050221

Contents?: true

Size: 1.48 KB

Versions: 10

Compression:

Stored size: 1.48 KB

Contents

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

          FIELDS = %w[id name system_name].freeze

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

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

              runner ListSubcommand
            end
          end

          def run
            printer.print_collection service.plans.map(&:attrs)
          end

          private

          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))
          end
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
3scale_toolbox-1.0.1 lib/3scale_toolbox/commands/plans_command/list_command.rb
3scale_toolbox-1.0.0 lib/3scale_toolbox/commands/plans_command/list_command.rb
3scale_toolbox-0.20.0 lib/3scale_toolbox/commands/plans_command/list_command.rb
3scale_toolbox-0.19.3 lib/3scale_toolbox/commands/plans_command/list_command.rb
3scale_toolbox-0.19.2 lib/3scale_toolbox/commands/plans_command/list_command.rb
3scale_toolbox-0.19.1 lib/3scale_toolbox/commands/plans_command/list_command.rb
3scale_toolbox-0.19.0 lib/3scale_toolbox/commands/plans_command/list_command.rb
3scale_toolbox-0.18.3 lib/3scale_toolbox/commands/plans_command/list_command.rb
3scale_toolbox-0.18.2 lib/3scale_toolbox/commands/plans_command/list_command.rb
3scale_toolbox-0.18.0 lib/3scale_toolbox/commands/plans_command/list_command.rb