Sha256: 009b7b75267cbaeb8250b515a92c79bace6a3184b2ab5430c2cfe7b43dc30c07

Contents?: true

Size: 1.48 KB

Versions: 6

Compression:

Stored size: 1.48 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'
              runner ListSubcommand

              param :remote
            end
          end

          def run
            activedocs = remote.list_activedocs
            print_activedocs_data(activedocs, ACTIVEDOCS_FIELDS_TO_SHOW)
          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 print_activedocs_data(activedocs, fields_to_show)
            print_header(fields_to_show)
            print_results(activedocs, fields_to_show)
          end

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

          def print_results(activedocs, fields_to_show)
            activedocs.each do |activedoc|
              puts fields_to_show.map { |field| activedoc.fetch(field, '(empty)') }.join("\t")
            end
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
3scale_toolbox-0.14.0 lib/3scale_toolbox/commands/activedocs_command/list_command.rb
3scale_toolbox-0.13.0 lib/3scale_toolbox/commands/activedocs_command/list_command.rb
3scale_toolbox-0.12.4 lib/3scale_toolbox/commands/activedocs_command/list_command.rb
3scale_toolbox-0.12.3 lib/3scale_toolbox/commands/activedocs_command/list_command.rb
3scale_toolbox-0.12.2 lib/3scale_toolbox/commands/activedocs_command/list_command.rb
3scale_toolbox-0.11.0 lib/3scale_toolbox/commands/activedocs_command/list_command.rb