#!/usr/bin/env node

var shell = require('../../lib/spawn').shell;
require('../../lib/prototype');
var processArgs = require('../../lib/args');
var file = require('../../lib/file');
var path = require('path');

console.error = function () { }

var argMap = processArgs(process.argv.slice(2));
var cwd = process.cwd();
var cmd = path.resolve(__dirname, '../../bin/7za.exe');
var output = cwd;
var input = "";

(async () => {
    for (var k in argMap) {
        switch (k) {
            case '-o':
                output = path.resolve(cwd, argMap[k])
                break;
            default:
                if (!path.isAbsolute(k)) {
                    input = path.resolve(cwd, k)
                } else {
                    input = k;
                }
                break;
        }
    }

    console.log(`解压目录：\r\n\t${output}`)
    console.log(`解压文件：\r\n\t${input}`)

    var args = ['x', `-o${output}`, '-y', input];
    var opts = { cwd }
    shell({ cmd, args, opts })
        .then(function ({ error, stdout }) {
            console.log(error, stdout)
        })
})()