<commit_before>require 'formatador'

module CloudConductorCli
  module Helpers
    module Output
      def display_message(message, indent_level: 0, indent_spaces: 2)
        indent = ' ' * indent_level * indent_spaces
        puts indent + message
      end

      def display_list(data, exclude_keys: [])
        display_data = data
        display_data = filter(display_data, exclude_keys) unless exclude_keys.empty?
        if display_data.empty?
          display_message 'No records'
        else
          Formatador.display_compact_table(display_data, display_data.first.keys)
        end
      end

      def display_details(data, exclude_keys: [])
        display_data = data
        display_data = filter(display_data, exclude_keys) unless exclude_keys.empty?
        display_data = verticalize(display_data)
        Formatador.display_compact_table(display_data)
      end

      def verticalize(data)
        return data unless data.is_a? Hash
        data.map do |key, value|
          { property: key, value: value }
        end
      end

      def filter(data, exclude_keys = [])
        case data
        when Array
          data.map do |record|
            record.reject { |key, _value| exclude_keys.include?(key) }
          end
        when Hash
          data.reject { |key, _value| exclude_keys.include?(key) }
        else
          data
        end
      end

      def error_exit(message, exit_code = 1)
        warn "Error: #{message}"
        exit exit_code
      end

      def normal_exit(message = nil, exit_code = 0)
        display_message message if message
        exit exit_code
      end
    end
  end
end<commit_msg>Change logic to use message of response body<commit_after>require 'formatador'

module CloudConductorCli
  module Helpers
    module Output
      def display_message(message, indent_level: 0, indent_spaces: 2)
        indent = ' ' * indent_level * indent_spaces
        puts indent + message
      end

      def display_list(data, exclude_keys: [])
        display_data = data
        display_data = filter(display_data, exclude_keys) unless exclude_keys.empty?
        if display_data.empty?
          display_message 'No records'
        else
          Formatador.display_compact_table(display_data, display_data.first.keys)
        end
      end

      def display_details(data, exclude_keys: [])
        display_data = data
        display_data = filter(display_data, exclude_keys) unless exclude_keys.empty?
        display_data = verticalize(display_data)
        Formatador.display_compact_table(display_data)
      end

      def verticalize(data)
        return data unless data.is_a? Hash
        data.map do |key, value|
          { property: key, value: value }
        end
      end

      def filter(data, exclude_keys = [])
        case data
        when Array
          data.map do |record|
            record.reject { |key, _value| exclude_keys.include?(key) }
          end
        when Hash
          data.reject { |key, _value| exclude_keys.include?(key) }
        else
          data
        end
      end

      def error_exit(message, response = nil, exit_code = 1)
        warn "Error: #{message}"
        warn "#{JSON.parse(response.body)['message']}" if response
        exit exit_code
      rescue JSON::ParserError
        warn response.body if response
        exit exit_code
      end

      def normal_exit(message = nil, exit_code = 0)
        display_message message if message
        exit exit_code
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.0710833096388968, 'fraction_numerical': 0.002274665908444697, 'mean_word_length': 2.1636690647482015, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4614264', 'n_tokens_mistral': 1000, 'n_tokens_neox': 974, 'n_words': 264}