<commit_before>// @flow

import './fs'
import Command from 'cli-engine-command'
import {buildConfig, type Config, type ConfigOptions} from 'cli-engine-config'
import Output from 'cli-engine-command/lib/output'
import Plugins from './plugins'
import {timeout} from './util'

import Analytics from './analytics'
import Updater from './updater'
import NotFound from './not_found'

import MigrateV5Plugins from './plugins/migrator'

import Help from './commands/help'

const debug = require('debug')('cli-engine:cli')
const handleEPIPE = err => { if (err.code !== 'EPIPE') throw err }

let out: Output
process.once('SIGINT', () => {
  if (out) {
    if (out.action.task) out.action.stop(out.color.red('ctrl-c'))
    out.exit(1)
  } else {
    process.exit(1)
  }
})
let handleErr = err => {
  if (!out) throw err
  out.error(err)
}
process.once('uncaughtException', handleErr)
process.once('unhandledRejection', handleErr)
process.stdout.on('error', handleEPIPE)
process.stderr.on('error', handleEPIPE)

export default class Main {
  mock: boolean
  argv: string[]
  config: Config
  cmd: Command<*>

  constructor (options: {argv: string[], config?: ConfigOptions, mock?: boolean}) {
    this.mock = !!options.mock
    this.argv = options.argv
    this.config = buildConfig(options.config)
    out = new Output({config: this.config, mock: this.mock})
  }

  async run () {
    debug('starting run')<commit_msg>conditionally set process handlers<commit_after>// @flow

import './fs'
import Command from 'cli-engine-command'
import {buildConfig, type Config, type ConfigOptions} from 'cli-engine-config'
import Output from 'cli-engine-command/lib/output'
import Plugins from './plugins'
import {timeout} from './util'

import Analytics from './analytics'
import Updater from './updater'
import NotFound from './not_found'

import MigrateV5Plugins from './plugins/migrator'

import Help from './commands/help'

const debug = require('debug')('cli-engine:cli')
const handleEPIPE = err => { if (err.code !== 'EPIPE') throw err }

let out: Output
if (!global.testing) {
  process.once('SIGINT', () => {
    if (out) {
      if (out.action.task) out.action.stop(out.color.red('ctrl-c'))
      out.exit(1)
    } else {
      process.exit(1)
    }
  })
  let handleErr = err => {
    if (!out) throw err
    out.error(err)
  }
  process.once('uncaughtException', handleErr)
  process.once('unhandledRejection', handleErr)
  process.stdout.on('error', handleEPIPE)
  process.stderr.on('error', handleEPIPE)
}

export default class Main {
  mock: boolean
  argv: string[]
  config: Config
  cmd: Command<*>

  constructor (options: {argv: string[], config?: ConfigOptions, mock?: boolean}) {
    this.mock = !!options.mock
    this.argv = options.argv
    this.config = buildConfig(options.config)
    out = new Output({config: this.config, mock: this.mock})
  }

  async run () {
    debug('starting run')
{'fraction_non_alphanumeric': 0.15214384508990317, 'fraction_numerical': 0.002074688796680498, 'mean_word_length': 3.996545768566494, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '42226', 'n_tokens_mistral': 932, 'n_tokens_neox': 920, 'n_words': 250}