<commit_before><commit_msg>Add frontend.rb to run the tool easily<commit_after>require "optparse"
require "pathname"
require "yaml"
require "pp"
require "open3"

$Verbose = false
$Config = Pathname(".nullabilint.yml")
$Executable = "./tool"

additional_options = []

OptionParser.new do |opt|
  opt.on("-v", "--verbose") { $Verbose = true }
  opt.on("-c CONFIG", "--config=CONFIG") {|path| $Config = Pathname(path) }
  opt.on("-e PATH", "--executable=CONFIG") {|executable| $Executable = executable }
  opt.on("-X OPTION") {|option| additional_options << option }
end.parse!(ARGV)

unless $Config.file?
  STDERR.puts "Configuration file #{$Config} not found."
end

config = $Config.file? ? YAML.load($Config.open) : {}

options = (config[:commandline_options] || []) + additional_options

for arg in ARGV
  command_line = [$Executable, arg, "--"] + options

  stdout, stderr, status = Open3.capture3(*command_line)

  if $Verbose || !status.success?
    puts command_line.join(" ")
  end

  unless status.success?
    STDERR.puts "Failed to execute analyzer..."
    STDERR.puts stderr
    exit 1
  else
    if $Verbose
      STDERR.puts stderr
    end

    STDOUT.puts stdout
  end
end

{'fraction_non_alphanumeric': 0.1551433389544688, 'fraction_numerical': 0.003372681281618887, 'mean_word_length': 3.9458333333333333, 'pattern_counts': {'":': 0, '<': 5, '<?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': '2424484', 'n_tokens_mistral': 423, 'n_tokens_neox': 407, 'n_words': 102}