Sha256: bcca7ba9781d18101c7e693ea9aabc3d672c5d1f4f43f56b68399e9e71b22d6a

Contents?: true

Size: 1.74 KB

Versions: 13

Compression:

Stored size: 1.74 KB

Contents

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

          def self.command
            Cri::Command.define do
              name        'list'
              usage       'list <remote>'
              summary     'List ActiveDocs'
              description 'List all defined ActiveDocs'

              ThreeScaleToolbox::CLI.output_flag(self)
              param :remote
              option :s, :'service-ref', "Filter the ActiveDocs by Service reference", argument: :required

              runner ListSubcommand
            end
          end

          def run
            printer.print_collection filtered_activedocs
          end

          private

          ACTIVEDOCS_FIELDS_TO_SHOW = %w[
            id name system_name service_id published
            skip_swagger_validations created_at updated_at
          ]

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

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

          def service_ref_filter
            options[:'service-ref']
          end

          def filters
            res = []
            if !service_ref_filter.nil?
              res << AttributeFilters::ServiceIDFilterFromServiceRef.new(remote, service_ref_filter, "service_id")
            end
            res
          end

          def filtered_activedocs
            filters.reduce(remote.list_activedocs) do |current_list, filter|
              filter.filter(current_list)
            end
          end
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

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