<commit_before>require 'open3'

module PerconaMigrator

  # It executes pt-online-schema-change commands in a new process and gets its
  # output and status
  class Runner

    NONE = "\e[0m"
    CYAN = "\e[38;5;86m"
    GREEN = "\e[32m"
    RED = "\e[31m"

    # Executes the given command printing the output to the logger
    #
    # @param command [String]
    # @param logger [IO]
    def self.execute(command, logger)
      new(command, logger).execute
    end

    # Constructor
    #
    # @param logger [IO]
    def initialize(logger)
      @logger = logger
      @status = nil
    end

    # Runs and logs the given command
    #
    # @param command [String]
    # @return [Boolean]
    def execute(command)
      @command = command

      log_started
      run_command
      log_finished

      status
    end

    private

    attr_reader :command, :logger, :status

    # TODO: log as a migration logger subitem
    #
    # Logs when the execution started
    def log_started
      logger.info "\n#{CYAN}-- #{command}#{NONE}\n\n"
    end

    # Executes the command outputing any errors
    #
    # @raise [Errno::ENOENT] if pt-online-schema-change can't be found<commit_msg>Log start and end through block<commit_after>require 'open3'

module PerconaMigrator

  # It executes pt-online-schema-change commands in a new process and gets its
  # output and status
  class Runner

    NONE = "\e[0m"
    CYAN = "\e[38;5;86m"
    GREEN = "\e[32m"
    RED = "\e[31m"

    # Executes the given command printing the output to the logger
    #
    # @param command [String]
    # @param logger [IO]
    def self.execute(command, logger)
      new(command, logger).execute
    end

    # Constructor
    #
    # @param logger [IO]
    def initialize(logger)
      @logger = logger
      @status = nil
    end

    # Runs and logs the given command
    #
    # @param command [String]
    # @return [Boolean]
    def execute(command)
      @command = command
      logging { run_command }
      status
    end

    private

    attr_reader :command, :logger, :status

    # Logs the start and end of the execution
    #
    # @yield
    def logging
      log_started
      yield
      log_finished
    end

    # TODO: log as a migration logger subitem
    #
    # Logs when the execution started
    def log_started
      logger.info "\n#{CYAN}-- #{command}#{NONE}\n\n"
    end

    # Executes the command outputing any errors
    #
    # @raise [Errno::ENOENT] if pt-online-schema-change can't be found
{'fraction_non_alphanumeric': 0.09330143540669857, 'fraction_numerical': 0.008771929824561403, 'mean_word_length': 2.2926509186351707, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5084229', 'n_tokens_mistral': 821, 'n_tokens_neox': 778, 'n_words': 252}