<commit_before>require 'trollop'
require 'lib/repl'
require 'lib/configuration'
require 'lib/query_output'
require 'lib/teradata'

@opts = Trollop::options do
  opt :hostname, "Teradata host name", :type => String
  opt :username, "Teradata username", :type => String
  opt :password, "<PASSWORD>", :type => String
  opt :command, "Teradata SQL command", :type => String
  opt :delimiter, "Column delimiter", :type => String, :default => "\t"
  opt :quotechar, "The quote character", :type => String, :default => '"'
  opt :file, "Teradata sql file", :type => String
  opt :output, "File to write the output to", :type => String
  opt :timeout, "Command timeout in seconds", :type => Integer, :default => 60
  opt :header, "Print column headers in output", :default => false
  opt :conf, "Configuration file file path", :type => String
end

def main()
  # Get config settings from all the following locations. Locations further down 
  # the list override previously defined settings with the same key.
  config_locations = [
    "#{File.expand_path File.dirname(__FILE__)}/tdsql.conf", 
    "#{File.expand_path '~/'}/.tdsql.conf", # Hidden conf file in user home directory
    @opts[:conf],
    @opts
  ]

  configuration = Configuration.new(*config_locations)
  sql_cmd = configuration[:sql_cmd]

  Teradata.open(configuration[:host]) do |db|
    if sql_cmd.nil?
      Repl.new(db, configuration)
    else
      begin
        results = db.select(configuration[:sql_cmd], configuration[:timeout])
      rescue Teradata => e
        $stderr.puts "Teradata Error: #{e.message}"
        return
      end

      output = QueryOutput.new(configuration)
      if @opts[:output] 
        File.open(@opts[:output], 'w') do |file|
          output.stream(results, file)
        end
      else
        output.stream(results, $stdout)
      end
    end
  end
end    

if __FILE__ == $PROGRAM_NAME
  main()
end<commit_msg>using absolute paths for require statements<commit_after>require 'trollop'
require "#{File.dirname(__FILE__)}/lib/repl"
require "#{File.dirname(__FILE__)}/lib/configuration"
require "#{File.dirname(__FILE__)}/lib/query_output"
require "#{File.dirname(__FILE__)}/lib/teradata"

@opts = Trollop::options do
  opt :hostname, "Teradata host name", :type => String
  opt :username, "Teradata username", :type => String
  opt :password, "<PASSWORD>", :type => String
  opt :command, "Teradata SQL command", :type => String
  opt :delimiter, "Column delimiter", :type => String, :default => "\t"
  opt :quotechar, "The quote character", :type => String, :default => '"'
  opt :file, "Teradata sql file", :type => String
  opt :output, "File to write the output to", :type => String
  opt :timeout, "Command timeout in seconds", :type => Integer, :default => 60
  opt :header, "Print column headers in output", :default => false
  opt :conf, "Configuration file file path", :type => String
end

def main()
  # Get config settings from all the following locations. Locations further down 
  # the list override previously defined settings with the same key.

  # TODO: Only read the conf file if it's permissions are 400
  config_locations = [
    "#{File.expand_path File.dirname(__FILE__)}/tdsql.conf", 
    "#{File.expand_path '~/'}/.tdsql.conf", # Hidden conf file in user home directory
    @opts[:conf],
    @opts
  ]

  configuration = Configuration.new(*config_locations)
  sql_cmd = configuration[:sql_cmd]

  Teradata.open(configuration[:host]) do |db|
    if sql_cmd.nil?
      Repl.new(db, configuration)
    else
      begin
        results = db.select(configuration[:sql_cmd], configuration[:timeout])
      rescue Teradata => e
        $stderr.puts "Teradata Error: #{e.message}"
        return
      end

      output = QueryOutput.new(configuration)
      if @opts[:output] 
        File.open(@opts[:output], 'w') do |file|
          output.stream(results, file)
        end
      else
        output.stream(results, $stdout)
      end
    end
  end
end    

if __FILE__ == $PROGRAM_NAME
  main()
end
{'fraction_non_alphanumeric': 0.13212241851206769, 'fraction_numerical': 0.0017417267977108733, 'mean_word_length': 3.573378839590444, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 35, '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': '1898580', 'n_tokens_mistral': 1225, 'n_tokens_neox': 1197, 'n_words': 383}