_ = require "underscore"
path = require "path"
cp = require "child_process"
command = ({archive}, [cmd, args...], opts={}) ->
  _.defaults opts, stdio: [0, 1, 2]
  (d, f, done) ->
    x = {cwd: d}
    _.defaults x, opts
    g = path.resolve f
    flags = args.concat g
    flags.push('.') if archive
    e = cp.spawn cmd, flags, x
    e.on 'exit', done
exports.tar =
  extract: command archive: false,  ['tar', 'xvf']
  archive: command archive: true, ['tar', 'cvf']
exports.zip =
  extract: command archive: false, ['unzip']
  archive: command archive: true, ['zip', '-r']
exports.rar =
  extract: command archive: false, ['unrar', 'x']
