<commit_before>require 'optparse'
require 'yaml'
require 'chronic'
require 'command_line_reporter'

require 'papertrail/cli_helpers'
require 'papertrail_log_analyzer'
require 'papertrail_log_analyzer/log_parser'

module PapertrailLogAnalyzer
  class CLI
    include Papertrail::CliHelpers
    include CommandLineReporter

    attr_reader :options

    def initialize
      @options = {
        :configfile => nil
      }
    end

    def run
      if configfile = find_configfile
        configfile_options = load_configfile(configfile)
        options.merge!(configfile_options)
      end

      OptionParser.new do |opts|
        opts.banner = "Papertrail Log Aanlyzer"

        opts.on("-h", "--help", "Show usage") do |v|
          puts opts
          exit
        end
        opts.on("-c", "--configfile PATH", "Path to config (~/.papertrail.yml)") do |v|
          options[:configfile] = File.expand_path(v)
        end
        opts.on("-t", "--token TOKEN", "Papertrail API token") do |v|
          options[:token] = v
        end
        opts.on("-v", "--verbose", "Show details") do |v|
          options[:verbose] = true
        end
        opts.on("--min-time MIN", "Earliest time to search from.") do |v|
          options[:min_time] = v
        end
        opts.on("--max-time MAX", "Latest time to search from.") do |v|
          options[:max_time] = v
        end

        opts.separator usage
      end.parse!

      if options[:configfile]
        configfile_options = load_configfile(options[:configfile])
        options.merge!(configfile_options)
      end

      query_options = {}

      query_results = PapertrailLogAnalyzer::query(ARGV[0], options, query_options)
      display_results(PapertrailLogAnalyzer::LogParser.parse(query_results.events))
    end

    def display_results(results)
      table do
        row :header => true do
          column '', :width => 20<commit_msg>Don't error if there are no results.<commit_after>require 'optparse'
require 'yaml'
require 'chronic'
require 'command_line_reporter'

require 'papertrail/cli_helpers'
require 'papertrail_log_analyzer'
require 'papertrail_log_analyzer/log_parser'

module PapertrailLogAnalyzer
  class CLI
    include Papertrail::CliHelpers
    include CommandLineReporter

    attr_reader :options

    def initialize
      @options = {
        :configfile => nil
      }
    end

    def run
      if configfile = find_configfile
        configfile_options = load_configfile(configfile)
        options.merge!(configfile_options)
      end

      OptionParser.new do |opts|
        opts.banner = "Papertrail Log Aanlyzer"

        opts.on("-h", "--help", "Show usage") do |v|
          puts opts
          exit
        end
        opts.on("-c", "--configfile PATH", "Path to config (~/.papertrail.yml)") do |v|
          options[:configfile] = File.expand_path(v)
        end
        opts.on("-t", "--token TOKEN", "Papertrail API token") do |v|
          options[:token] = v
        end
        opts.on("-v", "--verbose", "Show details") do |v|
          options[:verbose] = true
        end
        opts.on("--min-time MIN", "Earliest time to search from.") do |v|
          options[:min_time] = v
        end
        opts.on("--max-time MAX", "Latest time to search from.") do |v|
          options[:max_time] = v
        end

        opts.separator usage
      end.parse!

      if options[:configfile]
        configfile_options = load_configfile(options[:configfile])
        options.merge!(configfile_options)
      end

      query_options = {}

      query_results = PapertrailLogAnalyzer::query(ARGV[0], options, query_options)

      if query_results.events.size > 0
        display_results(PapertrailLogAnalyzer::LogParser.parse(query_results.events))
      else
        puts "No events found"
      end
    end

    def display_results(results)
      table do
        row :header => true do
          column '', :width => 20
{'fraction_non_alphanumeric': 0.10975299210593328, 'fraction_numerical': 0.0017825311942959, 'mean_word_length': 2.3891285591026747, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, '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': '7467392', 'n_tokens_mistral': 1203, 'n_tokens_neox': 1172, 'n_words': 292}