<commit_before>require 'optparse'

class ConsolePrinter
  def self.difference(old_line, new_line, translations)
    puts "#{'-'.red} #{normalize(old_line).red}"
    puts "#{'+'.green} #{normalize(new_line).green} => #{translations.to_s.yellow}"
    puts "-"*40
  end
  def self.normalize(line)
    line.sub(/^\s*/, " ")
  end
end

class String
  def colorize(color_code)
    "\e[#{color_code}m#{self}\e[0m"
  end
  def red
    colorize(31)
  end
  def green
    colorize(32)
  end
  def yellow
    colorize(34)
  end
end

class IOAction
  def self.yes_or_no?(msg)
    puts "#{msg} (y|n)"
    arg = STDIN.gets.chomp
    if arg =~ /[yY](es)?/ then
      true
    elsif arg =~ /[nN]o?/ then
      false
    else
      puts "Provide either (y)es or (n)o!"
      self.yes_or_no?(msg)
    end
  end
end


class CommandLine
  def initialize(args)
    @usage = "Usage: translateSlim INPUT_FILENAME_OR_DIRECTORY [OUTPUT_FILENAME_OR_DIRECTORY] [Options]"
    if args.size < 1 then
      puts @usage
      exit
    end
    @args = args
    @opts = OptionParser.new(&method(:opt_scan))
  end

  def opt_scan(opts)
    opts.banner = @usage
    opts.on_tail('-h', '--help', 'Show this message') do
      puts opts
      exit
    end
    opts.on_tail('-d', '--diff', 'Uses unix diff or colordiff for full file comparison') do
      puts opts
      exit
    end
  end

  def main
    @opts.parse!(@args)
    input = @args.shift
    output = @args.shift
    unix_diff_mode = false

    if File.directory?(input) then
      FileUtils.walk(input).each do |inp|
        translate(intput, nil, unix_diff_mode)
      end
    elsif File.file?(input) then
      translate(input, output, unix_diff_mode)
    else
      raise "Please provide a file or directory!"
      exit
    end
  end

  def translate(input, output=nil, unix_diff_mode=false)
    puts "file=#{input} diff=#{unix_diff_mode}"
    TranslateSlim.new(input, output, unix_diff_mode).stream_mode
  end
end


<commit_msg>changed the way args are used<commit_after>require 'optparse'

class ConsolePrinter
  def self.difference(old_line, new_line, translations)
    puts "#{'-'.red} #{normalize(old_line).red}"
    puts "#{'+'.green} #{normalize(new_line).green} => #{translations.to_s.yellow}"
    puts "-"*40
  end
  def self.unix_diff(bak_path, file_path)
    result = "Please install colordiff or diff (brew install colordiff)"
    colordiff, diff = `which colordiff`, `which diff`
    if not colordiff.empty? then
      result = `colordiff #{bak_path} #{file_path}`
    elsif not diff.empty? then
      result =`diff #{bak_path} #{file_path}`
    end
    puts "#{result}"
  end
  def self.normalize(line)
    line.sub(/^\s*/, " ")
  end
end

class String
  def colorize(color_code)
    "\e[#{color_code}m#{self}\e[0m"
  end
  def red
    colorize(31)
  end
  def green
    colorize(32)
  end
  def yellow
    colorize(34)
  end
end

class IOAction
  def self.yes_or_no?(msg)
    puts "#{msg} (y|n)"
    arg = STDIN.gets.chomp
    if arg =~ /[yY](es)?/ then
      true
    elsif arg =~ /[nN]o?/ then
      false
    else
      puts "Provide either (y)es or (n)o!"
      self.yes_or_no?(msg)
    end
  end
end


class CommandLine
  def initialize
    @options = {}
    @opts = OptionParser.new(&method(:opt_scan)).parse!
  end

  def opt_scan(opts)
    opts.banner = "Usage: translateSlim INPUT_FILENAME_OR_DIRECTORY [OUTPUT_FILENAME_OR_DIRECTORY] [Options]"
    opts.on_tail('-h', '--help', 'Show this message') do
      puts opts
      exit
    end
    opts.on_tail('-d', '--diff', 'Uses unix diff or colordiff for full file comparison') do
      @options[:diff] = true
    end
  end

  def main
    @options[:input] = input = ARGV.shift
    @options[:output] = output = ARGV.shift

    if File.directory?(input) then
      FileUtils.walk(input).each do |inp|
        translate
      end
    elsif File.file?(input) then
      translate
    else
      raise "Please provide a file or directory!"
      exit
    end
  end

  def translate
    puts "file=#{@options[:input]} diff=#{@options[:diff]}"
    translate_slim = TranslateSlim.new(@options)
    if @options[:diff] then
      translate_slim.unix_diff_mode
    else
      translate_slim.stream_mode
    end
  end
end




{'fraction_non_alphanumeric': 0.12669039145907474, 'fraction_numerical': 0.0045077105575326215, 'mean_word_length': 2.8050541516245486, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 5, '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': '1146979', 'n_tokens_mistral': 1542, 'n_tokens_neox': 1535, 'n_words': 378}