<commit_before>module Produce
  class Config
    ASK_MESSAGES = {
      bundle_identifier: "App Identifier (Bundle ID, e.g. com.krausefx.app): ",
      app_name: "App Name: ",
      version: "Initial version number (e.g. '1.0'): ",
      sku: "SKU Number (e.g. '1234'): ",
      primary_language: "Primary Language (e.g. 'English', 'German'): "
    }

    attr_reader :config

    def self.shared_config
      @@shared ||= self.new
    end

    def self.shared_config= config
      @@shared = config
    end

    def env_options
      hash = {
        bundle_identifier: ENV['PRODUCE_APP_IDENTIFIER'],
        app_name: ENV['PRODUCE_APP_NAME'],
        version: ENV['PRODUCE_VERSION'],
        sku: ENV['PRODUCE_SKU'],
        skip_itc: skip_itc?(ENV['PRODUCE_SKIP_ITC'])
      }
      hash[:primary_language] = 
        ENV['PRODUCE_LANGUAGE'] if is_valid_language?(ENV['PRODUCE_LANGUAGE'])
      hash[:bundle_identifier] ||= CredentialsManager::AppfileConfig.try_fetch_value(:app_identifier)
      hash.delete_if { |key, value| value.nil? }
      hash
    end

    def initialize(options = {})
      @config = env_options.merge(options)
    end

    def self.val(key)
      raise "Please only pass symbols, no Strings to this method".red unless key.kind_of? Symbol

      unless self.shared_config.config.has_key? key
        self.shared_config.config[key] = ask(ASK_MESSAGES[key]) do |q|
          case key
          when :primary_language
            q.validate = lambda { |val| is_valid_language?(val) }
            q.responses[:not_valid] = "Please enter one of available languages: #{AvailableDefaultLanguages.all_langauges}"
          else
            q.validate = lambda { |val| !val.empty? }
            q.responses[:not_valid] = "#{key.to_s.gsub('_', ' ').capitalize} can't be blank"
          end
        end
      end

      return self.shared_config.config[key]
    end

    def is_valid_language? language
      language = language.split.map(&:capitalize).join(' ')
      if AvailableDefaultLanguages.all_langauges.include?(input)
        true
      else
        Helper.log.error "Could not find langauge #{language} - available languages: #{AvailableDefaultLanguages.all_langauges}"
        false
      else
    end

    def skip_itc? value
      %w( true t 1 yes y ).include? value.to_s.downcase
    end
  end
end<commit_msg>better error message for primary language<commit_after>module Produce
  class Config
    ASK_MESSAGES = {
      bundle_identifier: "App Identifier (Bundle ID, e.g. com.krausefx.app): ",
      app_name: "App Name: ",
      version: "Initial version number (e.g. '1.0'): ",
      sku: "SKU Number (e.g. '1234'): ",
      primary_language: "Primary Language (e.g. 'English', 'German'): "
    }

    attr_reader :config

    def self.shared_config
      @@shared ||= self.new
    end

    def self.shared_config= config
      @@shared = config
    end

    def env_options
      hash = {
        bundle_identifier: ENV['PRODUCE_APP_IDENTIFIER'],
        app_name: ENV['PRODUCE_APP_NAME'],
        version: ENV['PRODUCE_VERSION'],
        sku: ENV['PRODUCE_SKU'],
        skip_itc: skip_itc?(ENV['PRODUCE_SKIP_ITC'])
      }
      if ENV['PRODUCE_LANGUAGE']
        language = ENV['PRODUCE_LANGUAGE']
        if is_valid_language?(language)
          hash[:primary_language] = language
        else
          Helper.log.error "PRODUCE_LANGUAGE is set to #{language} but it's not one of available languages. You'll be asked to set language again if needed."
        end
      end
      hash[:bundle_identifier] ||= CredentialsManager::AppfileConfig.try_fetch_value(:app_identifier)
      hash.delete_if { |key, value| value.nil? }
      hash
    end

    def initialize(options = {})
      @config = env_options.merge(options)
    end

    def self.val(key)
      raise "Please only pass symbols, no Strings to this method".red unless key.kind_of? Symbol

      unless self.shared_config.config.has_key? key
        self.shared_config.config[key] = ask(ASK_MESSAGES[key]) do |q|
          case key
          when :primary_language
            q.validate = lambda { |val| is_valid_language?(val) }
            q.responses[:not_valid] = "Please enter one of available languages: #{AvailableDefaultLanguages.all_langauges}"
          else
            q.validate = lambda { |val| !val.empty? }
            q.responses[:not_valid] = "#{key.to_s.gsub('_', ' ').capitalize} can't be blank"
          end
        end
      end

      return self.shared_config.config[key]
    end

    def is_valid_language? language
      language = language.split.map(&:capitalize).join(' ')
      AvailableDefaultLanguages.all_langauges.include? language
    end

    def skip_itc? value
      %w( true t 1 yes y ).include? value.to_s.downcase
    end
  end
end
{'fraction_non_alphanumeric': 0.11287958115183246, 'fraction_numerical': 0.002931937172774869, 'mean_word_length': 2.615442846328539, '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': '7447933', 'n_tokens_mistral': 1547, 'n_tokens_neox': 1500, 'n_words': 350}