"use strict";
var invalid_argument_names_error_1 = require("./errors/invalid-argument-names-error");
var invalid_timeout_value_error_1 = require("./errors/invalid-timeout-value-error");
var duplicate_cli_argument_error_1 = require("./errors/duplicate-cli-argument-error");
var missing_argument_value_error_1 = require("./errors/missing-argument-value-error");
var AlsatianCliOptions = (function () {
function AlsatianCliOptions(args) {
this._timeout = null;
args = this._extractFileGlobs(args);
args = this._extractTimeout(args);
if (args.length > 0) {
throw new invalid_argument_names_error_1.InvalidArgumentNamesError(args);
}
}
Object.defineProperty(AlsatianCliOptions.prototype, "fileGlobs", {
get: function () {
return this._fileGlobs;
},
enumerable: true,
configurable: true
});
Object.defineProperty(AlsatianCliOptions.prototype, "timeout", {
get: function () {
return this._timeout;
},
enumerable: true,
configurable: true
});
AlsatianCliOptions.prototype._extractFileGlobs = function (args) {
var _this = this;
this._fileGlobs = args.filter(function (value, index) {
var previousArgument = args[index - 1];
if ((!previousArgument || previousArgument[0]) !== "-" && value[0] !== "-") {
return true;
}
return false;
});
return args.filter(function (value) { return _this._fileGlobs.indexOf(value) === -1; });
};
AlsatianCliOptions.prototype._extractTimeout = function (args) {
var timeoutValue = this._getArgumentValueFromArgumentList(args, "timeout", "t");
if (timeoutValue !== null) {
var timeout = parseInt(timeoutValue);
if (isNaN(timeout) || timeout < 1 || timeout.toString() !== timeoutValue) {
throw new invalid_timeout_value_error_1.InvalidTimeoutValueError(timeoutValue);
}
this._timeout = timeout;
var argumentIndex_1 = this._getArgumentIndexFromArgumentList(args, "timeout", "t");
return args.filter(function (value, index) {
return index !== argumentIndex_1 && index !== argumentIndex_1 + 1;
});
}
return args;
};
AlsatianCliOptions.prototype._getArgumentIndexFromArgumentList = function (args, argumentName, argumentShorthand) {
var matchingArguments = args.filter(function (value, index) { return value === "--" + argumentName || value === "-" + argumentShorthand; });
if (matchingArguments.length === 0) {
return -1;
}
else if (matchingArguments.length > 1) {
throw new duplicate_cli_argument_error_1.DuplicateCliArgumentError(argumentName);
}
return args.indexOf(matchingArguments[0]);
};
AlsatianCliOptions.prototype._getArgumentValueFromArgumentList = function (args, argumentName, argumentShorthand) {
var argumentIndex = this._getArgumentIndexFromArgumentList(args, argumentName, argumentShorthand);
if (argumentIndex === -1) {
return null;
}
var valueArgument = args[argumentIndex + 1];
if (valueArgument && (valueArgument[0] !== "-" || !isNaN(parseInt(valueArgument)))) {
return valueArgument;
}
else {
throw new missing_argument_value_error_1.MissingArgumentValueError(argumentName);
}
};
return AlsatianCliOptions;
}());
exports.AlsatianCliOptions = AlsatianCliOptions;
//# sourceMappingURL=alsatian-cli-options.js.map |