<commit_before>require 'terminal-table'
require 'optparse'
require 'net/http'
require 'yaml'

module Hummer::Client
  class Command
    def initialize(config = nil)
      @options = {
          :server => "http://0.0.0.0:3000"
      }
      if config
        config = File.expand_path(config)
        unless File.exist? config
          puts "Config file not found: #{config}"
          exit(1)
        end
        @options = YAML.load_file config if File.exist? config
      else
        config = File.expand_path("~/.hummer")
        @options = YAML.load_file config if File.exist? config
      end
      @options = Hash[@options.map{|a| [a.first.to_sym, a.last]}]

      parser = OptionParser.new do|opts|
        opts.banner = "Usage: hummer [options] [command]"
        opts.separator ""
        opts.separator "Specific commands: projects suites post"
        opts.separator ""
        opts.separator "Specific options:"
        opts.on('--help', 'Display help' ) do
          @options[:help] = true
        end
        opts.on('--user ID', 'User ID' ) do |id|
          @options[:user] = id
        end
        opts.on('--token ID', 'User token' ) do |id|
          @options[:token] = id
        end
        opts.on('--server URL', 'Server URL' ) do |url|
          @options[:server] = url
        end
        opts.on('--project ID', 'Project ID' ) do |id|
          @options[:project] = id
        end
        opts.on('--suite ID', 'Suite ID' ) do |id|
          @options[:suite] = id
        end
        opts.on('--json', 'Output in JSON format' ) do
          @options[:json] = true
        end
        opts.on('--file FILE', 'XML file with test results') do |file|
          @options[:file] = file
        end
      end
      begin
        parser.parse ARGV
        if @options[:help] or ARGV.empty?
          puts parser
          exit(0)
        end
      rescue => e
        puts e.message
      end
    end
    def run
      API.configure(@options)
      command = ARGV.first
      if "projects" == command
        @projects = API.get()
        if @options[:json]
          puts @projects.inspect
        else
          rows = []
          rows << ["ID","Name"]
          rows << :separator
          @projects.each do |project|
            rows << [project["id"],project["name"]]
          end
          table = Terminal::Table.new :rows => rows
          puts table
        end
      elsif "post" == command
        if @options[:project] and @options[:file]

        else
          puts "Need project and file"
        end
      elsif "suites" == command
        if @options.has_key? :project
          @suites = API.get(:project => @options[:project], :suite => nil)
          if @options[:json]
            puts @suites.inspect
          else
            rows = []
            rows << ["ID","Build","Tests","Errors","Failures","Skip","Passed"]
            rows << :separator
            @suites.each do |suite|
              rows << [suite["id"],suite["build"],suite["total_tests"],suite["total_errors"],suite["total_failures"],suite["total_skip"],suite["total_passed"]]
            end
            table = Terminal::Table.new :rows => rows
            puts table
          end
        else
          puts "Need project"
          exit(1)
        end<commit_msg>add outputs<commit_after>require 'terminal-table'
require 'optparse'
require 'net/http'
require 'yaml'

module Hummer::Client
  class Command
    def initialize(config = nil)
      @options = {
          :server => "http://0.0.0.0:3000"
      }
      if config
        config = File.expand_path(config)
        unless File.exist? config
          puts "Config file not found: #{config}"
          exit(1)
        end
        @options = YAML.load_file config if File.exist? config
      else
        config = File.expand_path("~/.hummer")
        @options = YAML.load_file config if File.exist? config
      end
      @options = Hash[@options.map{|a| [a.first.to_sym, a.last]}]

      parser = OptionParser.new do|opts|
        opts.banner = "Usage: hummer [options] [command]"
        opts.separator ""
        opts.separator "Specific commands: projects suites post"
        opts.separator ""
        opts.separator "Specific options:"
        opts.on('--help', 'Display help' ) do
          @options[:help] = true
        end
        opts.on('--user ID', 'User ID' ) do |id|
          @options[:user] = id
        end
        opts.on('--token ID', 'User token' ) do |id|
          @options[:token] = id
        end
        opts.on('--server URL', 'Server URL' ) do |url|
          @options[:server] = url
        end
        opts.on('--project ID', 'Project ID' ) do |id|
          @options[:project] = id
        end
        opts.on('--suite ID', 'Suite ID' ) do |id|
          @options[:suite] = id
        end
        opts.on('--json', 'Output in JSON format' ) do
          @options[:json] = true
        end
        opts.on('--file FILE', 'XML file with test results') do |file|
          @options[:file] = file
        end
      end
      begin
        parser.parse ARGV
        if @options[:help] or ARGV.empty?
          puts parser
          exit(0)
        end
      rescue => e
        puts e.message
      end
    end
    def run
      API.configure(@options)
      command = ARGV.first
      if "projects" == command
        @projects = API.get()
        if @options[:json]
          puts @projects.inspect
        else
          rows = []
          rows << ["ID","Name","Features","Owner"]
          rows << :separator
          @projects.each do |project|
            rows << [project["id"],project["name"],project["feature_list"].join(", "),project["owner_name"]]
          end
          table = Terminal::Table.new :rows => rows
          puts table
        end
      elsif "post" == command
        if @options[:project] and @options[:file]

        else
          puts "Need project and file"
        end
      elsif "suites" == command
        if @options.has_key? :project
          @suites = API.get(:project => @options[:project], :suite => nil)
          if @options[:json]
            puts @suites.inspect
          else
            rows = []
            rows << ["ID","Build","Tests","Errors","Failures","Skip","Passed","Features","Owner"]
            rows << :separator
            @suites.each do |suite|
              rows << [suite["id"],suite["build"],suite["total_tests"],suite["total_errors"],suite["total_failures"],suite["total_skip"],suite["total_passed"],suite["feature_list"].join(", "),suite["user_name"]]
            end
            table = Terminal::Table.new :rows => rows
            puts table
          end
        else
          puts "Need project"
          exit(1)
        end
{'fraction_non_alphanumeric': 0.13806470851349337, 'fraction_numerical': 0.0032801550618756525, 'mean_word_length': 1.7696118909991743, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '5189203', 'n_tokens_mistral': 1948, 'n_tokens_neox': 1919, 'n_words': 502}