"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var libs_1 = require("./libs");
var Command = (function () {
    function Command(start) {
        this._cmd = '';
        if (start) {
            this._cmd = start.toString();
        }
    }
    Command.prototype.add = function (value, include) {
        include = libs_1.value.defaultValue(include, true);
        var cmd = this._cmd;
        if (include) {
            if (!cmd.endsWith('\n')) {
                cmd += ' ';
            }
            cmd += value.toString();
        }
        return new Command(cmd);
    };
    Command.prototype.addLine = function (value, include) {
        return this.add(value, include).newLine(include);
    };
    Command.prototype.newLine = function (include) {
        include = libs_1.value.defaultValue(include, true);
        var cmd = this._cmd;
        if (include) {
            cmd = this._cmd + "\n";
        }
        return new Command(cmd);
    };
    Command.prototype.arg = function (value, include) {
        return this.add("--" + trimArg(value), include);
    };
    Command.prototype.alias = function (value, include) {
        return this.add("-" + trimArg(value), include);
    };
    Object.defineProperty(Command.prototype, "value", {
        get: function () {
            var newLine = this._cmd.endsWith('\n');
            var cmd = this._cmd.trim();
            if (newLine) {
                cmd += '\n';
            }
            return cmd;
        },
        enumerable: true,
        configurable: true
    });
    Command.prototype.toString = function () {
        return this.value;
    };
    Command.prototype.clone = function () {
        return new Command(this);
    };
    Command.prototype.run = function (options) {
        if (options === void 0) { options = {}; }
        return libs_1.exec.run(this.toString(), options);
    };
    return Command;
}());
exports.Command = Command;
exports.command = function (start) { return new Command(start); };
function trimArg(value) {
    return value
        .trim()
        .replace(/^\-*/, '')
        .trim();
}
//# sourceMappingURL=command.js.map