<commit_before>'use strict'

import _debug from 'debug'
const debug = _debug('chiffchaff:SpawnTask')

import Task from 'chiffchaff'
import defaults from 'defaults'
import spawn from 'win-spawn'
import Promise from 'bluebird'
import {Stream} from 'stream'

const toBuffer = data => (typeof data === 'string') ? new Buffer(data) : data

export default class SpawnTask extends Task {
  constructor (command, args, source, options) {
    super()
    this._command = command
    this._args = args
    this._source = source
    this._options = defaults(options, {
      env: process.env,
      captureStdout: false,
      captureStderr: false
    })
    this._proc = null
    this._stdout = new Buffer(0)
    this._stderr = new Buffer(0)
    this._piped = false
  }

  get source () {
    return this._source
  }

  set source (src) {
    this._source = src
  }

  get command () {
    return this._command
  }

  get args () {
    return this._args
  }

  _start () {
    return new Promise((resolve, reject) => {
      this._resolve = resolve
      this._reject = reject
      this._runCommand()
      this._addListeners()
      this._pipeSource()
    })
      .cancellable()
      .catch(Promise.CancellationError, err => {
        debug(`Process ${this.command} cancelled`)
        throw err
      })
  }

  _runCommand () {
    debug(`Running ${this.command} with args: ${this.args}`)
    this._proc = spawn(this.command, this.args, this._options)
    this._proc.stdout.setEncoding('utf8')
    this._proc.stderr.setEncoding('utf8')
  }

  _addListeners () {<commit_msg>Making args and command settable<commit_after>'use strict'

import _debug from 'debug'
const debug = _debug('chiffchaff:SpawnTask')

import Task from 'chiffchaff'
import defaults from 'defaults'
import spawn from 'win-spawn'
import Promise from 'bluebird'
import {Stream} from 'stream'

const toBuffer = data => (typeof data === 'string') ? new Buffer(data) : data

export default class SpawnTask extends Task {
  constructor (command, args, source, options) {
    super()
    this._command = command
    this._args = args
    this._source = source
    this._options = defaults(options, {
      env: process.env,
      captureStdout: false,
      captureStderr: false
    })
    this._proc = null
    this._stdout = new Buffer(0)
    this._stderr = new Buffer(0)
    this._piped = false
  }

  get source () {
    return this._source
  }

  set source (src) {
    this._source = src
  }

  get command () {
    return this._command
  }

  set command (command) {
    this._command = command
  }

  get args () {
    return this._args
  }

  set args (args) {
    this._args = args
  }

  _start () {
    return new Promise((resolve, reject) => {
      this._resolve = resolve
      this._reject = reject
      this._runCommand()
      this._addListeners()
      this._pipeSource()
    })
      .cancellable()
      .catch(Promise.CancellationError, err => {
        debug(`Process ${this.command} cancelled`)
        throw err
      })
  }

  _runCommand () {
    debug(`Running ${this.command} with args: ${this.args}`)
    this._proc = spawn(this.command, this.args, this._options)
    this._proc.stdout.setEncoding('utf8')
    this._proc.stderr.setEncoding('utf8')
  }

  _addListeners () {
{'fraction_non_alphanumeric': 0.12082183379331493, 'fraction_numerical': 0.0024532352039251764, 'mean_word_length': 2.7974388824214205, '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': '6526424', 'n_tokens_mistral': 1015, 'n_tokens_neox': 1001, 'n_words': 262}