<commit_before>require "aqbanking/version"
require "aqbanking/user"
require "aqbanking/account"

module AqBanking
  def self.config=(path)
    @config = path
  end

  def self.config
    @config ||= '.'
  end

  def with_secure_pin(user, pin, &block)
    f = Tempfile.new("pin_#{user.bank}_#{user.user_id}", '/tmp')
    File.chmod(0400, f.path)

    f.write "PIN_#{user.bank}_#{user.user_id} = \"#{pin}\"\n"
    f.flush

    yield f if block_given?

    f.close
    f.unlink
  end

  def aqhbci(command, options = {})
    options = {
      pinfile: nil,
      args: ['--acceptvalidcerts', '--noninteractive',
             '--charset=utf-8', "--cfgfile=#{AqBanking.config}"]
    }.merge(options)
    "aqhbci-tool4 #{options[:args].join(' ')} #{command}"
  end

  def aqcli(command, options = {})
    options = {
      pinfile: nil,
      args: ['--acceptvalidcerts', '--noninteractive',
             '--charset=utf-8', "--cfgdir=#{AqBanking.config}"]
    }.merge(options)
    "aqbanking-cli #{options[:args].join(' ')} #{command}"
  end
end
<commit_msg>Refactor the command argument generation<commit_after>require "aqbanking/version"
require "aqbanking/user"
require "aqbanking/account"

module AqBanking
  ARGS = {
    acceptvalidcerts: :flag,
    noninteractive: :flag,
    charset: :value,
    cfgdir: :value,
    cfgfile: :value,
    pinfile: :value
  }

  def self.config=(path)
    @config = path
  end

  def self.config
    @config ||= '.'
  end

  def with_secure_pin(user, pin, &block)
    f = Tempfile.new("pin_#{user.bank}_#{user.user_id}", '/tmp')
    File.chmod(0400, f.path)

    f.write "PIN_#{user.bank}_#{user.user_id} = \"#{pin}\"\n"
    f.flush

    yield f if block_given?

    f.close
    f.unlink
  end

  def aqhbci(command, options = {})
    options = {
      pinfile: nil,
      acceptvalidcerts: true,
      noninteractive: true,
      charset: 'utf-8',
      cfgfile: AqBanking.config
    }.merge(options)
    "aqhbci-tool4 #{generate_arguments(options)} #{command}"
  end

  def aqcli(command, options = {})
    options = {
      pinfile: nil,
      acceptvalidcerts: true,
      noninteractive: true,
      charset: 'utf-8',
      cfgdir: AqBanking.config
    }.merge(options)
    "aqbanking-cli #{generate_arguments(options)} #{command}"
  end

  private
  def generate_arguments(hash)
    ARGS.keys.map do |key|
      if ARGS[key] == :flag && hash[key]
        "--#{key.to_s}"
      elsif ARGS[key] == :value && hash[key]
        "--#{key.to_s}=#{hash[key]}"
      end
    end.compact.join(' ')
  end
end

{'fraction_non_alphanumeric': 0.16554986204178163, 'fraction_numerical': 0.005518328734726055, 'mean_word_length': 2.7937219730941703, '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': '2831928', 'n_tokens_mistral': 960, 'n_tokens_neox': 933, 'n_words': 182}