<commit_before>require 'optparse'
require 'json'
require 'logger'
require 'fileutils'

module XScheduler

  module Submit

    LOG_ROTATE_SIZE = 7

    extend self

    def run(argv)
      scheduler = XScheduler.load_scheduler
      parameters = {}
      logger = Logger.new(STDERR)
      work_dir = '.'

      OptionParser.new { |parser|
        parser.on('-t', '--show-template', 'show template') do |t|
          raise "scheduler type is not given" unless scheduler
          h = {parameters: scheduler.parameter_definitions, template: scheduler.template }
          $stdout.print JSON.pretty_generate(h)
          exit
        end

        parser.on('-p', '--parameters [PARAM]', 'parameters') do |param|
          parameters = JSON.load(param.sub(/^=/,'')) if param.size > 0
        end

        parser.on('-l', '--log [LOGFILE]', 'log file name') do |log|
          if log.size > 0
            logfile = log.sub(/^=/,'')
            logger = Logger.new(logfile , LOG_ROTATE_SIZE)
          end
        end

        parser.on('-d', '--dir [WORKDIR]', 'work directory') do |dir|
          if dir.size > 0
            work_dir = dir.sub(/^=/, '')
            FileUtils.mkdir_p(work_dir)
          end
        end

      }.parse!(argv)

      raise "scheduler type is not given" unless scheduler
      raise "you should give one argument" unless argv.size == 1
      output = scheduler.submit(argv[0], parameters, logger: logger, work_dir: work_dir)
      $stdout.print JSON.pretty_generate(output)

    end
  end

  module Status

    extend self

    def run(argv)
      OptionParser.new.parse!(argv)

      scheduler = XScheduler.load_scheduler
      raise "scheduler type is not given" unless scheduler
      job_id = argv[0]
      if job_id
        output = scheduler.status(job_id)
      else
        output = scheduler.all_status
      end
      $stdout.print JSON.pretty_generate(output)
    end
  end

  module Delete

    extend self
<commit_msg>trivial update<commit_after>require 'optparse'
require 'json'
require 'logger'
require 'fileutils'

module XScheduler

  module Submit

    LOG_ROTATE_SIZE = 7

    extend self

    def run(argv)
      scheduler = XScheduler.load_scheduler
      parameters = {}
      logger = Logger.new(STDERR)
      work_dir = '.'

      OptionParser.new { |parser|
        parser.on('-t', '--show-template', 'show template') do |t|
          raise "scheduler type is not given" unless scheduler
          h = {parameters: scheduler.parameter_definitions, template: scheduler.template }
          $stdout.print JSON.pretty_generate(h)
          exit
        end

        parser.on('-p', '--parameters [PARAM]', 'parameters') do |param|
          parameters = JSON.load(param.sub(/^=/,'')) if param.size > 0
        end

        parser.on('-l', '--log [LOGFILE]', 'log file name') do |log|
          if log.size > 0
            logfile = log.sub(/^=/,'')
            logger = Logger.new(logfile , LOG_ROTATE_SIZE)
          end
        end

        parser.on('-d', '--dir [WORKDIR]', 'work directory') do |dir|
          if dir.size > 0
            work_dir = dir.sub(/^=/, '')
            FileUtils.mkdir_p(work_dir)
          end
        end

      }.parse!(argv)

      raise "scheduler type is not given" unless scheduler
      raise "you should give a script to submit" unless argv.size == 1
      output = scheduler.submit(argv[0], parameters, logger: logger, work_dir: work_dir)
      $stdout.print JSON.pretty_generate(output)

    end
  end

  module Status

    extend self

    def run(argv)
      OptionParser.new.parse!(argv)

      scheduler = XScheduler.load_scheduler
      raise "scheduler type is not given" unless scheduler
      job_id = argv[0]
      if job_id
        output = scheduler.status(job_id)
      else
        output = scheduler.all_status
      end
      $stdout.print JSON.pretty_generate(output)
    end
  end

  module Delete

    extend self

{'fraction_non_alphanumeric': 0.11215906194239103, 'fraction_numerical': 0.0035686974254397143, 'mean_word_length': 2.149277688603531, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '6684874', 'n_tokens_mistral': 1235, 'n_tokens_neox': 1175, 'n_words': 319}