<commit_before>require 'methadone'

class Kb8Run

  include Methadone::Main
  include Methadone::CLILogging

  #API_VERSION = 'v1beta3'
  API_VERSION = 'v1'
  CMD_ROLLING_UPDATE = "kubectl --api-version=\"#{API_VERSION}\" rolling-update %s-v%s -f -"
  CMD_CREATE = 'kubectl create -f -'
  CMD_GET_POD = "kubectl --api-version=\"#{API_VERSION}\" get pods -l %s=%s -o yaml"
  CMD_GET_EVENTS = "kubectl --api-version=\"#{API_VERSION}\" get events -o yaml"
  CMD_DELETE_PODS = 'kubectl delete pods -l %s=%s'
  CMD_CONFIG_CLUSTER = 'kubectl config set-cluster %s --server=%s'
  CMD_CONFIG_CONTEXT = 'kubectl config set-context default-context --cluster=%s'
  CMD_CONFIG_DEFAULT = 'kubectl config use-context default-context'

  def self.run(cmd, capture=false, term_output=true, input=nil)

    # pipe if specifying input
    if input
      mode = 'w+'
    else
      mode = 'r'
    end

    output = ''
    # Run process and capture output if required...
    debug "Running:'#{cmd}', '#{mode}'"
    pid = nil
    IO.popen(cmd, mode) do |subprocess|
      pid = subprocess.pid
      if input
        debug "#{input}"
        subprocess.write(input)
        subprocess.close_write
      end
      subprocess.read.split("\n").each do |line|
        puts line if term_output
        output << "#{line}\n"  if capture
      end
    end
    if capture<commit_msg>Fixed error detection when kubectl actually does error<commit_after>require 'methadone'

class Kb8Run

  include Methadone::Main
  include Methadone::CLILogging

  #API_VERSION = 'v1beta3'
  API_VERSION = 'v1'
  CMD_ROLLING_UPDATE = "kubectl --api-version=\"#{API_VERSION}\" rolling-update %s-v%s -f -"
  CMD_CREATE = 'kubectl create -f -'
  CMD_GET_POD = "kubectl --api-version=\"#{API_VERSION}\" get pods -l %s=%s -o yaml"
  CMD_GET_EVENTS = "kubectl --api-version=\"#{API_VERSION}\" get events -o yaml"
  CMD_DELETE_PODS = 'kubectl delete pods -l %s=%s'
  CMD_CONFIG_CLUSTER = 'kubectl config set-cluster %s --server=%s'
  CMD_CONFIG_CONTEXT = 'kubectl config set-context default-context --cluster=%s'
  CMD_CONFIG_DEFAULT = 'kubectl config use-context default-context'

  def self.run(cmd, capture=false, term_output=true, input=nil)

    # pipe if specifying input
    if input
      mode = 'w+'
    else
      mode = 'r'
    end

    output = ''
    # Run process and capture output if required...
    debug "Running:'#{cmd}', '#{mode}'"
    pid = nil
    IO.popen(cmd, mode) do |subprocess|
      pid = subprocess.pid
      if input
        debug "#{input}"
        subprocess.write(input)
        subprocess.close_write
      end
      subprocess.read.split("\n").each do |line|
        puts line if term_output
        output << "#{line}\n"  if capture
      end
      subprocess.close
      unless $?.success?
        raise "Error running #{cmd}:\n#{output}"
      end
    end
    if capture
{'fraction_non_alphanumeric': 0.1306937631394534, 'fraction_numerical': 0.002803083391730904, 'mean_word_length': 2.8843537414965987, 'pattern_counts': {'":': 0, '<': 7, '<?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': '3986822', 'n_tokens_mistral': 1029, 'n_tokens_neox': 1003, 'n_words': 252}