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

          FIELDS_TO_SHOW = %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'

              param       :remote
              param       :service_ref

              runner ListSubcommand
            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
            service.plans.each do |plan|
              puts FIELDS_TO_SHOW.map { |field| plan.fetch(field, '(empty)') }.join("\t")
            end
          end

          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
        end
      end
    end
  end
end<commit_msg>structured output: application plan list command<commit_after>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
          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
{'fraction_non_alphanumeric': 0.06078740157480315, 'fraction_numerical': 0.0, 'mean_word_length': 1.3525925925925926, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2272710', 'n_tokens_mistral': 789, 'n_tokens_neox': 758, 'n_words': 207}